-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_sensor.py
More file actions
49 lines (39 loc) · 1.58 KB
/
binary_sensor.py
File metadata and controls
49 lines (39 loc) · 1.58 KB
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 sensor platform for NECTOR200."""
from __future__ import annotations
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
OUTPUT_SENSORS = (
("compressor_output", "Compressor"),
("defrost_output", "Defrost Output"),
("fan_output", "Fan"),
("light_output", "Light Output"),
("alarm_relay_output", "Alarm Relay"),
("auxiliary_relay_output", "Auxiliary Relay"),
("hot_resistance_output", "Hot Resistance"),
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up NECTOR200 binary sensors."""
coordinator = hass.data[DOMAIN][config_entry.entry_id]
async_add_entities(
NECTOR200OutputBinarySensor(coordinator, config_entry, key, name)
for key, name in OUTPUT_SENSORS
)
class NECTOR200OutputBinarySensor(CoordinatorEntity, BinarySensorEntity):
"""Binary output state from NECTOR200 IO data."""
def __init__(self, coordinator, config_entry, key: str, name: str):
"""Initialize the sensor."""
super().__init__(coordinator)
self._key = key
self._attr_unique_id = f"{config_entry.entry_id}_{key}"
self._attr_name = f"WH1 {name}"
@property
def is_on(self) -> bool:
"""Return true if the binary sensor is on."""
return bool(self.coordinator.data.get(self._key, False))