forked from elupus/hass_nibe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary_sensor.py
49 lines (36 loc) · 1.39 KB
/
binary_sensor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Binary sensors for nibe uplink."""
import logging
from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT, BinarySensorEntity
from homeassistant.exceptions import PlatformNotReady
from .const import CONF_BINARY_SENSORS, DATA_NIBE
from .entity import NibeParameterEntity
PARALLEL_UPDATES = 0
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, entry, async_add_entities):
"""Set up the device based on a config entry."""
if DATA_NIBE not in hass.data:
raise PlatformNotReady
uplink = hass.data[DATA_NIBE].uplink
systems = hass.data[DATA_NIBE].systems
entities = []
for system in systems.values():
for parameter_id in system.config[CONF_BINARY_SENSORS]:
entities.append(
NibeBinarySensor(uplink, system.system_id, parameter_id, entry)
)
async_add_entities(entities, True)
class NibeBinarySensor(NibeParameterEntity, BinarySensorEntity):
"""Binary sensor."""
def __init__(self, uplink, system_id, parameter_id, entry):
"""Init."""
super(NibeBinarySensor, self).__init__(
uplink, system_id, parameter_id, None, ENTITY_ID_FORMAT
)
@property
def is_on(self):
"""Return if sensor is on."""
data = self._parameters[self._parameter_id]
if data:
return data["rawValue"] == "1"
else:
return None