Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Support for the for Danfoss Air HRV sensors."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from pydanfossair.commands import ReadCommand
8 
10  SensorDeviceClass,
11  SensorEntity,
12  SensorStateClass,
13 )
14 from homeassistant.const import PERCENTAGE, REVOLUTIONS_PER_MINUTE, UnitOfTemperature
15 from homeassistant.core import HomeAssistant
16 from homeassistant.helpers.entity_platform import AddEntitiesCallback
17 from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
18 
19 from . import DOMAIN as DANFOSS_AIR_DOMAIN
20 
21 _LOGGER = logging.getLogger(__name__)
22 
23 
25  hass: HomeAssistant,
26  config: ConfigType,
27  add_entities: AddEntitiesCallback,
28  discovery_info: DiscoveryInfoType | None = None,
29 ) -> None:
30  """Set up the available Danfoss Air sensors etc."""
31  data = hass.data[DANFOSS_AIR_DOMAIN]
32 
33  sensors = [
34  [
35  "Danfoss Air Exhaust Temperature",
36  UnitOfTemperature.CELSIUS,
37  ReadCommand.exhaustTemperature,
38  SensorDeviceClass.TEMPERATURE,
39  SensorStateClass.MEASUREMENT,
40  ],
41  [
42  "Danfoss Air Outdoor Temperature",
43  UnitOfTemperature.CELSIUS,
44  ReadCommand.outdoorTemperature,
45  SensorDeviceClass.TEMPERATURE,
46  SensorStateClass.MEASUREMENT,
47  ],
48  [
49  "Danfoss Air Supply Temperature",
50  UnitOfTemperature.CELSIUS,
51  ReadCommand.supplyTemperature,
52  SensorDeviceClass.TEMPERATURE,
53  SensorStateClass.MEASUREMENT,
54  ],
55  [
56  "Danfoss Air Extract Temperature",
57  UnitOfTemperature.CELSIUS,
58  ReadCommand.extractTemperature,
59  SensorDeviceClass.TEMPERATURE,
60  SensorStateClass.MEASUREMENT,
61  ],
62  [
63  "Danfoss Air Remaining Filter",
64  PERCENTAGE,
65  ReadCommand.filterPercent,
66  None,
67  None,
68  ],
69  [
70  "Danfoss Air Humidity",
71  PERCENTAGE,
72  ReadCommand.humidity,
73  SensorDeviceClass.HUMIDITY,
74  SensorStateClass.MEASUREMENT,
75  ],
76  ["Danfoss Air Fan Step", PERCENTAGE, ReadCommand.fan_step, None, None],
77  [
78  "Danfoss Air Exhaust Fan Speed",
79  REVOLUTIONS_PER_MINUTE,
80  ReadCommand.exhaust_fan_speed,
81  None,
82  None,
83  ],
84  [
85  "Danfoss Air Supply Fan Speed",
86  REVOLUTIONS_PER_MINUTE,
87  ReadCommand.supply_fan_speed,
88  None,
89  None,
90  ],
91  [
92  "Danfoss Air Dial Battery",
93  PERCENTAGE,
94  ReadCommand.battery_percent,
95  SensorDeviceClass.BATTERY,
96  None,
97  ],
98  ]
99 
100  add_entities(
101  (
102  DanfossAir(data, sensor[0], sensor[1], sensor[2], sensor[3], sensor[4])
103  for sensor in sensors
104  ),
105  True,
106  )
107 
108 
110  """Representation of a Sensor."""
111 
112  def __init__(self, data, name, sensor_unit, sensor_type, device_class, state_class):
113  """Initialize the sensor."""
114  self._data_data = data
115  self._attr_name_attr_name = name
116  self._attr_native_value_attr_native_value = None
117  self._type_type = sensor_type
118  self._attr_native_unit_of_measurement_attr_native_unit_of_measurement = sensor_unit
119  self._attr_device_class_attr_device_class = device_class
120  self._attr_state_class_attr_state_class = state_class
121 
122  def update(self) -> None:
123  """Update the new state of the sensor.
124 
125  This is done through the DanfossAir object that does the actual
126  communication with the Air CCM.
127  """
128  self._data_data.update()
129 
130  self._attr_native_value_attr_native_value = self._data_data.get_value(self._type_type)
131  if self._attr_native_value_attr_native_value is None:
132  _LOGGER.debug("Could not get data for %s", self._type_type)
def __init__(self, data, name, sensor_unit, sensor_type, device_class, state_class)
Definition: sensor.py:112
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
Definition: sensor.py:29
def add_entities(account, async_add_entities, tracked)
Definition: sensor.py:40
float|int|str|None get_value(Sensor sensor, str field)
Definition: sensor.py:46