forked from elupus/hass_nibe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_sensor.py
47 lines (35 loc) · 1.41 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
"""Binary sensors for nibe uplink."""
from __future__ import annotations
import logging
from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT, BinarySensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from nibeuplink.typing import ParameterId
from . import NibeData, NibeSystem
from .const import CONF_BINARY_SENSORS, DATA_NIBE_ENTRIES
from .entity import NibeParameterEntity
PARALLEL_UPDATES = 0
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities
):
"""Set up the device based on a config entry."""
data: NibeData = hass.data[DATA_NIBE_ENTRIES][entry.entry_id]
entities = []
for system in data.systems.values():
for parameter_id in system.config[CONF_BINARY_SENSORS]:
entities.append(NibeBinarySensor(system, parameter_id))
async_add_entities(entities, True)
class NibeBinarySensor(NibeParameterEntity, BinarySensorEntity):
"""Binary sensor."""
def __init__(self, system: NibeSystem, parameter_id: ParameterId):
"""Init."""
super().__init__(system, parameter_id, None, ENTITY_ID_FORMAT)
@property
def is_on(self):
"""Return if sensor is on."""
data = self.get_parameter[self._parameter_id]
if data:
return data["rawValue"] == "1"
else:
return None