Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for the for Danfoss Air HRV binary sensors."""
2 
3 from __future__ import annotations
4 
5 from pydanfossair.commands import ReadCommand
6 
8  BinarySensorDeviceClass,
9  BinarySensorEntity,
10 )
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
14 
15 from . import DOMAIN as DANFOSS_AIR_DOMAIN
16 
17 
19  hass: HomeAssistant,
20  config: ConfigType,
21  add_entities: AddEntitiesCallback,
22  discovery_info: DiscoveryInfoType | None = None,
23 ) -> None:
24  """Set up the available Danfoss Air sensors etc."""
25  data = hass.data[DANFOSS_AIR_DOMAIN]
26 
27  sensors = [
28  [
29  "Danfoss Air Bypass Active",
30  ReadCommand.bypass,
31  BinarySensorDeviceClass.OPENING,
32  ],
33  ["Danfoss Air Away Mode Active", ReadCommand.away_mode, None],
34  ]
35 
37  (
38  DanfossAirBinarySensor(data, sensor[0], sensor[1], sensor[2])
39  for sensor in sensors
40  ),
41  True,
42  )
43 
44 
46  """Representation of a Danfoss Air binary sensor."""
47 
48  def __init__(self, data, name, sensor_type, device_class):
49  """Initialize the Danfoss Air binary sensor."""
50  self._data_data = data
51  self._attr_name_attr_name = name
52  self._type_type = sensor_type
53  self._attr_device_class_attr_device_class = device_class
54 
55  def update(self) -> None:
56  """Fetch new state data for the sensor."""
57  self._data_data.update()
58 
59  self._attr_is_on_attr_is_on = self._data_data.get_value(self._type_type)
def __init__(self, data, name, sensor_type, device_class)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
float|int|str|None get_value(Sensor sensor, str field)
Definition: sensor.py:46