2019-04-03 15:40:03 +00:00
|
|
|
"""Demo platform that has two fake binary sensors."""
|
2020-09-12 21:20:30 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
2020-09-13 14:33:54 +00:00
|
|
|
DEVICE_CLASS_MOISTURE,
|
2020-09-12 21:20:30 +00:00
|
|
|
DEVICE_CLASS_MOTION,
|
|
|
|
BinarySensorEntity,
|
|
|
|
)
|
2019-12-08 16:59:27 +00:00
|
|
|
|
2019-11-13 15:37:31 +00:00
|
|
|
from . import DOMAIN
|
2015-11-19 18:00:22 +00:00
|
|
|
|
|
|
|
|
2019-11-13 15:37:31 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the Demo binary sensor platform."""
|
2019-11-13 15:37:31 +00:00
|
|
|
async_add_entities(
|
2019-07-31 19:25:30 +00:00
|
|
|
[
|
2020-09-13 14:33:54 +00:00
|
|
|
DemoBinarySensor(
|
|
|
|
"binary_1", "Basement Floor Wet", False, DEVICE_CLASS_MOISTURE
|
|
|
|
),
|
2020-09-12 21:20:30 +00:00
|
|
|
DemoBinarySensor(
|
|
|
|
"binary_2", "Movement Backyard", True, DEVICE_CLASS_MOTION
|
|
|
|
),
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
|
|
|
)
|
2015-11-19 18:00:22 +00:00
|
|
|
|
|
|
|
|
2019-11-13 15:37:31 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up the Demo config entry."""
|
|
|
|
await async_setup_platform(hass, {}, async_add_entities)
|
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class DemoBinarySensor(BinarySensorEntity):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""representation of a Demo binary sensor."""
|
2016-03-07 19:21:08 +00:00
|
|
|
|
2019-11-13 15:37:31 +00:00
|
|
|
def __init__(self, unique_id, name, state, device_class):
|
2016-03-07 19:21:08 +00:00
|
|
|
"""Initialize the demo sensor."""
|
2019-11-13 15:37:31 +00:00
|
|
|
self._unique_id = unique_id
|
2015-11-20 13:58:49 +00:00
|
|
|
self._name = name
|
2015-11-19 18:00:22 +00:00
|
|
|
self._state = state
|
2017-02-11 04:46:15 +00:00
|
|
|
self._sensor_type = device_class
|
2016-02-19 01:59:58 +00:00
|
|
|
|
2019-11-13 15:37:31 +00:00
|
|
|
@property
|
|
|
|
def device_info(self):
|
|
|
|
"""Return device info."""
|
|
|
|
return {
|
|
|
|
"identifiers": {
|
|
|
|
# Serial numbers are unique identifiers within a specific domain
|
|
|
|
(DOMAIN, self.unique_id)
|
|
|
|
},
|
|
|
|
"name": self.name,
|
|
|
|
}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return the unique id."""
|
|
|
|
return self._unique_id
|
|
|
|
|
2016-02-19 01:59:58 +00:00
|
|
|
@property
|
2017-02-11 04:46:15 +00:00
|
|
|
def device_class(self):
|
2016-02-22 09:11:46 +00:00
|
|
|
"""Return the class of this sensor."""
|
2016-02-19 01:59:58 +00:00
|
|
|
return self._sensor_type
|
2015-11-19 18:00:22 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
2016-02-22 09:11:46 +00:00
|
|
|
"""No polling needed for a demo binary sensor."""
|
2015-11-19 18:00:22 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the name of the binary sensor."""
|
2015-11-19 18:00:22 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return true if the binary sensor is on."""
|
2015-11-19 18:00:22 +00:00
|
|
|
return self._state
|