Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Support for HomematicIP Cloud sensors."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Callable
6 from typing import Any
7 
8 from homematicip.aio.device import (
9  AsyncBrandSwitchMeasuring,
10  AsyncEnergySensorsInterface,
11  AsyncFloorTerminalBlock6,
12  AsyncFloorTerminalBlock10,
13  AsyncFloorTerminalBlock12,
14  AsyncFullFlushSwitchMeasuring,
15  AsyncHeatingThermostat,
16  AsyncHeatingThermostatCompact,
17  AsyncHeatingThermostatEvo,
18  AsyncHomeControlAccessPoint,
19  AsyncLightSensor,
20  AsyncMotionDetectorIndoor,
21  AsyncMotionDetectorOutdoor,
22  AsyncMotionDetectorPushButton,
23  AsyncPassageDetector,
24  AsyncPlugableSwitchMeasuring,
25  AsyncPresenceDetectorIndoor,
26  AsyncRoomControlDeviceAnalog,
27  AsyncTemperatureDifferenceSensor2,
28  AsyncTemperatureHumiditySensorDisplay,
29  AsyncTemperatureHumiditySensorOutdoor,
30  AsyncTemperatureHumiditySensorWithoutDisplay,
31  AsyncWeatherSensor,
32  AsyncWeatherSensorPlus,
33  AsyncWeatherSensorPro,
34  AsyncWiredFloorTerminalBlock12,
35 )
36 from homematicip.base.enums import FunctionalChannelType, ValveState
37 from homematicip.base.functionalChannels import (
38  FloorTerminalBlockMechanicChannel,
39  FunctionalChannel,
40 )
41 
43  SensorDeviceClass,
44  SensorEntity,
45  SensorStateClass,
46 )
47 from homeassistant.config_entries import ConfigEntry
48 from homeassistant.const import (
49  LIGHT_LUX,
50  PERCENTAGE,
51  UnitOfEnergy,
52  UnitOfPower,
53  UnitOfPrecipitationDepth,
54  UnitOfSpeed,
55  UnitOfTemperature,
56  UnitOfVolume,
57  UnitOfVolumeFlowRate,
58 )
59 from homeassistant.core import HomeAssistant
60 from homeassistant.helpers.entity_platform import AddEntitiesCallback
61 from homeassistant.helpers.typing import StateType
62 
63 from .const import DOMAIN
64 from .entity import HomematicipGenericEntity
65 from .hap import HomematicipHAP
66 from .helpers import get_channels_from_device
67 
68 ATTR_CURRENT_ILLUMINATION = "current_illumination"
69 ATTR_LOWEST_ILLUMINATION = "lowest_illumination"
70 ATTR_HIGHEST_ILLUMINATION = "highest_illumination"
71 ATTR_LEFT_COUNTER = "left_counter"
72 ATTR_RIGHT_COUNTER = "right_counter"
73 ATTR_TEMPERATURE_OFFSET = "temperature_offset"
74 ATTR_WIND_DIRECTION = "wind_direction"
75 ATTR_WIND_DIRECTION_VARIATION = "wind_direction_variation_in_degree"
76 ATTR_ESI_TYPE = "type"
77 ESI_TYPE_UNKNOWN = "UNKNOWN"
78 ESI_CONNECTED_SENSOR_TYPE_IEC = "ES_IEC"
79 ESI_CONNECTED_SENSOR_TYPE_GAS = "ES_GAS"
80 ESI_CONNECTED_SENSOR_TYPE_LED = "ES_LED"
81 
82 ESI_TYPE_CURRENT_POWER_CONSUMPTION = "CurrentPowerConsumption"
83 ESI_TYPE_ENERGY_COUNTER_USAGE_HIGH_TARIFF = "ENERGY_COUNTER_USAGE_HIGH_TARIFF"
84 ESI_TYPE_ENERGY_COUNTER_USAGE_LOW_TARIFF = "ENERGY_COUNTER_USAGE_LOW_TARIFF"
85 ESI_TYPE_ENERGY_COUNTER_INPUT_SINGLE_TARIFF = "ENERGY_COUNTER_INPUT_SINGLE_TARIFF"
86 ESI_TYPE_CURRENT_GAS_FLOW = "CurrentGasFlow"
87 ESI_TYPE_CURRENT_GAS_VOLUME = "GasVolume"
88 
89 ILLUMINATION_DEVICE_ATTRIBUTES = {
90  "currentIllumination": ATTR_CURRENT_ILLUMINATION,
91  "lowestIllumination": ATTR_LOWEST_ILLUMINATION,
92  "highestIllumination": ATTR_HIGHEST_ILLUMINATION,
93 }
94 
95 
96 async def async_setup_entry( # noqa: C901
97  hass: HomeAssistant,
98  config_entry: ConfigEntry,
99  async_add_entities: AddEntitiesCallback,
100 ) -> None:
101  """Set up the HomematicIP Cloud sensors from a config entry."""
102  hap = hass.data[DOMAIN][config_entry.unique_id]
103  entities: list[HomematicipGenericEntity] = []
104  for device in hap.home.devices:
105  if isinstance(device, AsyncHomeControlAccessPoint):
106  entities.append(HomematicipAccesspointDutyCycle(hap, device))
107  if isinstance(
108  device,
109  (
110  AsyncHeatingThermostat,
111  AsyncHeatingThermostatCompact,
112  AsyncHeatingThermostatEvo,
113  ),
114  ):
115  entities.append(HomematicipHeatingThermostat(hap, device))
116  entities.append(HomematicipTemperatureSensor(hap, device))
117  if isinstance(
118  device,
119  (
120  AsyncTemperatureHumiditySensorDisplay,
121  AsyncTemperatureHumiditySensorWithoutDisplay,
122  AsyncTemperatureHumiditySensorOutdoor,
123  AsyncWeatherSensor,
124  AsyncWeatherSensorPlus,
125  AsyncWeatherSensorPro,
126  ),
127  ):
128  entities.append(HomematicipTemperatureSensor(hap, device))
129  entities.append(HomematicipHumiditySensor(hap, device))
130  elif isinstance(device, (AsyncRoomControlDeviceAnalog,)):
131  entities.append(HomematicipTemperatureSensor(hap, device))
132  if isinstance(
133  device,
134  (
135  AsyncLightSensor,
136  AsyncMotionDetectorIndoor,
137  AsyncMotionDetectorOutdoor,
138  AsyncMotionDetectorPushButton,
139  AsyncPresenceDetectorIndoor,
140  AsyncWeatherSensor,
141  AsyncWeatherSensorPlus,
142  AsyncWeatherSensorPro,
143  ),
144  ):
145  entities.append(HomematicipIlluminanceSensor(hap, device))
146  if isinstance(
147  device,
148  (
149  AsyncPlugableSwitchMeasuring,
150  AsyncBrandSwitchMeasuring,
151  AsyncFullFlushSwitchMeasuring,
152  ),
153  ):
154  entities.append(HomematicipPowerSensor(hap, device))
155  entities.append(HomematicipEnergySensor(hap, device))
156  if isinstance(
157  device, (AsyncWeatherSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro)
158  ):
159  entities.append(HomematicipWindspeedSensor(hap, device))
160  if isinstance(device, (AsyncWeatherSensorPlus, AsyncWeatherSensorPro)):
161  entities.append(HomematicipTodayRainSensor(hap, device))
162  if isinstance(device, AsyncPassageDetector):
163  entities.append(HomematicipPassageDetectorDeltaCounter(hap, device))
164  if isinstance(device, AsyncTemperatureDifferenceSensor2):
165  entities.append(HomematicpTemperatureExternalSensorCh1(hap, device))
166  entities.append(HomematicpTemperatureExternalSensorCh2(hap, device))
167  entities.append(HomematicpTemperatureExternalSensorDelta(hap, device))
168  if isinstance(device, AsyncEnergySensorsInterface):
169  for ch in get_channels_from_device(
170  device, FunctionalChannelType.ENERGY_SENSORS_INTERFACE_CHANNEL
171  ):
172  if ch.connectedEnergySensorType == ESI_CONNECTED_SENSOR_TYPE_IEC:
173  if ch.currentPowerConsumption is not None:
174  entities.append(HmipEsiIecPowerConsumption(hap, device))
175  if ch.energyCounterOneType != ESI_TYPE_UNKNOWN:
176  entities.append(HmipEsiIecEnergyCounterHighTariff(hap, device))
177  if ch.energyCounterTwoType != ESI_TYPE_UNKNOWN:
178  entities.append(HmipEsiIecEnergyCounterLowTariff(hap, device))
179  if ch.energyCounterThreeType != ESI_TYPE_UNKNOWN:
180  entities.append(
182  )
183 
184  if ch.connectedEnergySensorType == ESI_CONNECTED_SENSOR_TYPE_GAS:
185  if ch.currentGasFlow is not None:
186  entities.append(HmipEsiGasCurrentGasFlow(hap, device))
187  if ch.gasVolume is not None:
188  entities.append(HmipEsiGasGasVolume(hap, device))
189 
190  if ch.connectedEnergySensorType == ESI_CONNECTED_SENSOR_TYPE_LED:
191  if ch.currentPowerConsumption is not None:
192  entities.append(HmipEsiLedCurrentPowerConsumption(hap, device))
193  entities.append(HmipEsiLedEnergyCounterHighTariff(hap, device))
194  if isinstance(
195  device,
196  (
197  AsyncFloorTerminalBlock6,
198  AsyncFloorTerminalBlock10,
199  AsyncFloorTerminalBlock12,
200  AsyncWiredFloorTerminalBlock12,
201  ),
202  ):
203  entities.extend(
205  hap, device, channel=channel.index
206  )
207  for channel in device.functionalChannels
208  if isinstance(channel, FloorTerminalBlockMechanicChannel)
209  and getattr(channel, "valvePosition", None) is not None
210  )
211 
212  async_add_entities(entities)
213 
214 
216  HomematicipGenericEntity, SensorEntity
217 ):
218  """Representation of the HomematicIP floor terminal block."""
219 
220  _attr_native_unit_of_measurement = PERCENTAGE
221  _attr_state_class = SensorStateClass.MEASUREMENT
222 
223  def __init__(
224  self, hap: HomematicipHAP, device, channel, is_multi_channel=True
225  ) -> None:
226  """Initialize floor terminal block 12 device."""
227  super().__init__(
228  hap,
229  device,
230  channel=channel,
231  is_multi_channel=is_multi_channel,
232  post="Valve Position",
233  )
234 
235  @property
236  def icon(self) -> str | None:
237  """Return the icon."""
238  if super().icon:
239  return super().icon
240  channel = next(
241  channel
242  for channel in self._device_device.functionalChannels
243  if channel.index == self._channel_channel
244  )
245  if channel.valveState != ValveState.ADAPTION_DONE:
246  return "mdi:alert"
247  return "mdi:heating-coil"
248 
249  @property
250  def native_value(self) -> int | None:
251  """Return the state of the floor terminal block mechanical channel valve position."""
252  channel = next(
253  channel
254  for channel in self._device_device.functionalChannels
255  if channel.index == self._channel_channel
256  )
257  if channel.valveState != ValveState.ADAPTION_DONE:
258  return None
259  return round(channel.valvePosition * 100)
260 
261 
263  """Representation of then HomeMaticIP access point."""
264 
265  _attr_icon = "mdi:access-point-network"
266  _attr_native_unit_of_measurement = PERCENTAGE
267  _attr_state_class = SensorStateClass.MEASUREMENT
268 
269  def __init__(self, hap: HomematicipHAP, device) -> None:
270  """Initialize access point status entity."""
271  super().__init__(hap, device, post="Duty Cycle")
272 
273  @property
274  def native_value(self) -> float:
275  """Return the state of the access point."""
276  return self._device_device.dutyCycleLevel
277 
278 
280  """Representation of the HomematicIP heating thermostat."""
281 
282  _attr_native_unit_of_measurement = PERCENTAGE
283 
284  def __init__(self, hap: HomematicipHAP, device) -> None:
285  """Initialize heating thermostat device."""
286  super().__init__(hap, device, post="Heating")
287 
288  @property
289  def icon(self) -> str | None:
290  """Return the icon."""
291  if super().icon:
292  return super().icon
293  if self._device_device.valveState != ValveState.ADAPTION_DONE:
294  return "mdi:alert"
295  return "mdi:radiator"
296 
297  @property
298  def native_value(self) -> int | None:
299  """Return the state of the radiator valve."""
300  if self._device_device.valveState != ValveState.ADAPTION_DONE:
301  return None
302  return round(self._device_device.valvePosition * 100)
303 
304 
306  """Representation of the HomematicIP humidity sensor."""
307 
308  _attr_device_class = SensorDeviceClass.HUMIDITY
309  _attr_native_unit_of_measurement = PERCENTAGE
310  _attr_state_class = SensorStateClass.MEASUREMENT
311 
312  def __init__(self, hap: HomematicipHAP, device) -> None:
313  """Initialize the thermometer device."""
314  super().__init__(hap, device, post="Humidity")
315 
316  @property
317  def native_value(self) -> int:
318  """Return the state."""
319  return self._device_device.humidity
320 
321 
323  """Representation of the HomematicIP thermometer."""
324 
325  _attr_device_class = SensorDeviceClass.TEMPERATURE
326  _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
327  _attr_state_class = SensorStateClass.MEASUREMENT
328 
329  def __init__(self, hap: HomematicipHAP, device) -> None:
330  """Initialize the thermometer device."""
331  super().__init__(hap, device, post="Temperature")
332 
333  @property
334  def native_value(self) -> float:
335  """Return the state."""
336  if hasattr(self._device_device, "valveActualTemperature"):
337  return self._device_device.valveActualTemperature
338 
339  return self._device_device.actualTemperature
340 
341  @property
342  def extra_state_attributes(self) -> dict[str, Any]:
343  """Return the state attributes of the windspeed sensor."""
344  state_attr = super().extra_state_attributes
345 
346  temperature_offset = getattr(self._device_device, "temperatureOffset", None)
347  if temperature_offset:
348  state_attr[ATTR_TEMPERATURE_OFFSET] = temperature_offset
349 
350  return state_attr
351 
352 
354  """Representation of the HomematicIP Illuminance sensor."""
355 
356  _attr_device_class = SensorDeviceClass.ILLUMINANCE
357  _attr_native_unit_of_measurement = LIGHT_LUX
358  _attr_state_class = SensorStateClass.MEASUREMENT
359 
360  def __init__(self, hap: HomematicipHAP, device) -> None:
361  """Initialize the device."""
362  super().__init__(hap, device, post="Illuminance")
363 
364  @property
365  def native_value(self) -> float:
366  """Return the state."""
367  if hasattr(self._device_device, "averageIllumination"):
368  return self._device_device.averageIllumination
369 
370  return self._device_device.illumination
371 
372  @property
373  def extra_state_attributes(self) -> dict[str, Any]:
374  """Return the state attributes of the wind speed sensor."""
375  state_attr = super().extra_state_attributes
376 
377  for attr, attr_key in ILLUMINATION_DEVICE_ATTRIBUTES.items():
378  if attr_value := getattr(self._device_device, attr, None):
379  state_attr[attr_key] = attr_value
380 
381  return state_attr
382 
383 
385  """Representation of the HomematicIP power measuring sensor."""
386 
387  _attr_device_class = SensorDeviceClass.POWER
388  _attr_native_unit_of_measurement = UnitOfPower.WATT
389  _attr_state_class = SensorStateClass.MEASUREMENT
390 
391  def __init__(self, hap: HomematicipHAP, device) -> None:
392  """Initialize the device."""
393  super().__init__(hap, device, post="Power")
394 
395  @property
396  def native_value(self) -> float:
397  """Return the power consumption value."""
398  return self._device_device.currentPowerConsumption
399 
400 
402  """Representation of the HomematicIP energy measuring sensor."""
403 
404  _attr_device_class = SensorDeviceClass.ENERGY
405  _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
406  _attr_state_class = SensorStateClass.TOTAL_INCREASING
407 
408  def __init__(self, hap: HomematicipHAP, device) -> None:
409  """Initialize the device."""
410  super().__init__(hap, device, post="Energy")
411 
412  @property
413  def native_value(self) -> float:
414  """Return the energy counter value."""
415  return self._device_device.energyCounter
416 
417 
419  """Representation of the HomematicIP wind speed sensor."""
420 
421  _attr_device_class = SensorDeviceClass.WIND_SPEED
422  _attr_native_unit_of_measurement = UnitOfSpeed.KILOMETERS_PER_HOUR
423  _attr_state_class = SensorStateClass.MEASUREMENT
424 
425  def __init__(self, hap: HomematicipHAP, device) -> None:
426  """Initialize the windspeed sensor."""
427  super().__init__(hap, device, post="Windspeed")
428 
429  @property
430  def native_value(self) -> float:
431  """Return the wind speed value."""
432  return self._device_device.windSpeed
433 
434  @property
435  def extra_state_attributes(self) -> dict[str, Any]:
436  """Return the state attributes of the wind speed sensor."""
437  state_attr = super().extra_state_attributes
438 
439  wind_direction = getattr(self._device_device, "windDirection", None)
440  if wind_direction is not None:
441  state_attr[ATTR_WIND_DIRECTION] = _get_wind_direction(wind_direction)
442 
443  wind_direction_variation = getattr(self._device_device, "windDirectionVariation", None)
444  if wind_direction_variation:
445  state_attr[ATTR_WIND_DIRECTION_VARIATION] = wind_direction_variation
446 
447  return state_attr
448 
449 
451  """Representation of the HomematicIP rain counter of a day sensor."""
452 
453  _attr_device_class = SensorDeviceClass.PRECIPITATION
454  _attr_native_unit_of_measurement = UnitOfPrecipitationDepth.MILLIMETERS
455  _attr_state_class = SensorStateClass.MEASUREMENT
456 
457  def __init__(self, hap: HomematicipHAP, device) -> None:
458  """Initialize the device."""
459  super().__init__(hap, device, post="Today Rain")
460 
461  @property
462  def native_value(self) -> float:
463  """Return the today's rain value."""
464  return round(self._device_device.todayRainCounter, 2)
465 
466 
468  """Representation of the HomematicIP device HmIP-STE2-PCB."""
469 
470  _attr_device_class = SensorDeviceClass.TEMPERATURE
471  _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
472  _attr_state_class = SensorStateClass.MEASUREMENT
473 
474  def __init__(self, hap: HomematicipHAP, device) -> None:
475  """Initialize the device."""
476  super().__init__(hap, device, post="Channel 1 Temperature")
477 
478  @property
479  def native_value(self) -> float:
480  """Return the state."""
481  return self._device_device.temperatureExternalOne
482 
483 
485  """Representation of the HomematicIP device HmIP-STE2-PCB."""
486 
487  _attr_device_class = SensorDeviceClass.TEMPERATURE
488  _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
489  _attr_state_class = SensorStateClass.MEASUREMENT
490 
491  def __init__(self, hap: HomematicipHAP, device) -> None:
492  """Initialize the device."""
493  super().__init__(hap, device, post="Channel 2 Temperature")
494 
495  @property
496  def native_value(self) -> float:
497  """Return the state."""
498  return self._device_device.temperatureExternalTwo
499 
500 
502  """Representation of the HomematicIP device HmIP-STE2-PCB."""
503 
504  _attr_device_class = SensorDeviceClass.TEMPERATURE
505  _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
506  _attr_state_class = SensorStateClass.MEASUREMENT
507 
508  def __init__(self, hap: HomematicipHAP, device) -> None:
509  """Initialize the device."""
510  super().__init__(hap, device, post="Delta Temperature")
511 
512  @property
513  def native_value(self) -> float:
514  """Return the state."""
515  return self._device_device.temperatureExternalDelta
516 
517 
519  """EntityDescription for HmIP-ESI Sensors."""
520 
521  def __init__(
522  self,
523  hap: HomematicipHAP,
524  device: HomematicipGenericEntity,
525  key: str,
526  value_fn: Callable[[FunctionalChannel], StateType],
527  type_fn: Callable[[FunctionalChannel], str],
528  ) -> None:
529  """Initialize Sensor Entity."""
530  super().__init__(
531  hap=hap,
532  device=device,
533  channel=1,
534  post=key,
535  is_multi_channel=False,
536  )
537 
538  self._value_fn_value_fn = value_fn
539  self._type_fn_type_fn = type_fn
540 
541  @property
542  def extra_state_attributes(self) -> dict[str, Any]:
543  """Return the state attributes of the esi sensor."""
544  state_attr = super().extra_state_attributes
545  state_attr[ATTR_ESI_TYPE] = self._type_fn_type_fn(self.functional_channelfunctional_channel)
546 
547  return state_attr
548 
549  @property
550  def native_value(self) -> str | None:
551  """Return the state of the sensor."""
552  return str(self._value_fn_value_fn(self.functional_channelfunctional_channel))
553 
554 
556  """Representation of the Hmip-ESI IEC currentPowerConsumption sensor."""
557 
558  _attr_device_class = SensorDeviceClass.POWER
559  _attr_native_unit_of_measurement = UnitOfPower.WATT
560  _attr_state_class = SensorStateClass.MEASUREMENT
561 
562  def __init__(self, hap: HomematicipHAP, device) -> None:
563  """Initialize the device."""
564  super().__init__(
565  hap,
566  device,
567  key="CurrentPowerConsumption",
568  value_fn=lambda channel: channel.currentPowerConsumption,
569  type_fn=lambda channel: "CurrentPowerConsumption",
570  )
571 
572 
574  """Representation of the Hmip-ESI IEC energyCounterOne sensor."""
575 
576  _attr_device_class = SensorDeviceClass.ENERGY
577  _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
578  _attr_state_class = SensorStateClass.TOTAL_INCREASING
579 
580  def __init__(self, hap: HomematicipHAP, device) -> None:
581  """Initialize the device."""
582  super().__init__(
583  hap,
584  device,
585  key=ESI_TYPE_ENERGY_COUNTER_USAGE_HIGH_TARIFF,
586  value_fn=lambda channel: channel.energyCounterOne,
587  type_fn=lambda channel: channel.energyCounterOneType,
588  )
589 
590 
592  """Representation of the Hmip-ESI IEC energyCounterTwo sensor."""
593 
594  _attr_device_class = SensorDeviceClass.ENERGY
595  _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
596  _attr_state_class = SensorStateClass.TOTAL_INCREASING
597 
598  def __init__(self, hap: HomematicipHAP, device) -> None:
599  """Initialize the device."""
600  super().__init__(
601  hap,
602  device,
603  key=ESI_TYPE_ENERGY_COUNTER_USAGE_LOW_TARIFF,
604  value_fn=lambda channel: channel.energyCounterTwo,
605  type_fn=lambda channel: channel.energyCounterTwoType,
606  )
607 
608 
610  """Representation of the Hmip-ESI IEC energyCounterThree sensor."""
611 
612  _attr_device_class = SensorDeviceClass.ENERGY
613  _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
614  _attr_state_class = SensorStateClass.TOTAL_INCREASING
615 
616  def __init__(self, hap: HomematicipHAP, device) -> None:
617  """Initialize the device."""
618  super().__init__(
619  hap,
620  device,
621  key=ESI_TYPE_ENERGY_COUNTER_INPUT_SINGLE_TARIFF,
622  value_fn=lambda channel: channel.energyCounterThree,
623  type_fn=lambda channel: channel.energyCounterThreeType,
624  )
625 
626 
628  """Representation of the Hmip-ESI Gas currentGasFlow sensor."""
629 
630  _attr_device_class = SensorDeviceClass.VOLUME_FLOW_RATE
631  _attr_native_unit_of_measurement = UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR
632  _attr_state_class = SensorStateClass.MEASUREMENT
633 
634  def __init__(self, hap: HomematicipHAP, device) -> None:
635  """Initialize the device."""
636  super().__init__(
637  hap,
638  device,
639  key="CurrentGasFlow",
640  value_fn=lambda channel: channel.currentGasFlow,
641  type_fn=lambda channel: "CurrentGasFlow",
642  )
643 
644 
646  """Representation of the Hmip-ESI Gas gasVolume sensor."""
647 
648  _attr_device_class = SensorDeviceClass.GAS
649  _attr_native_unit_of_measurement = UnitOfVolume.CUBIC_METERS
650  _attr_state_class = SensorStateClass.TOTAL_INCREASING
651 
652  def __init__(self, hap: HomematicipHAP, device) -> None:
653  """Initialize the device."""
654  super().__init__(
655  hap,
656  device,
657  key="GasVolume",
658  value_fn=lambda channel: channel.gasVolume,
659  type_fn=lambda channel: "GasVolume",
660  )
661 
662 
664  """Representation of the Hmip-ESI LED currentPowerConsumption sensor."""
665 
666  _attr_device_class = SensorDeviceClass.POWER
667  _attr_native_unit_of_measurement = UnitOfPower.WATT
668  _attr_state_class = SensorStateClass.MEASUREMENT
669 
670  def __init__(self, hap: HomematicipHAP, device) -> None:
671  """Initialize the device."""
672  super().__init__(
673  hap,
674  device,
675  key="CurrentPowerConsumption",
676  value_fn=lambda channel: channel.currentPowerConsumption,
677  type_fn=lambda channel: "CurrentPowerConsumption",
678  )
679 
680 
682  """Representation of the Hmip-ESI LED energyCounterOne sensor."""
683 
684  _attr_device_class = SensorDeviceClass.ENERGY
685  _attr_native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
686  _attr_state_class = SensorStateClass.TOTAL_INCREASING
687 
688  def __init__(self, hap: HomematicipHAP, device) -> None:
689  """Initialize the device."""
690  super().__init__(
691  hap,
692  device,
693  key=ESI_TYPE_ENERGY_COUNTER_USAGE_HIGH_TARIFF,
694  value_fn=lambda channel: channel.energyCounterOne,
695  type_fn=lambda channel: ESI_TYPE_ENERGY_COUNTER_USAGE_HIGH_TARIFF,
696  )
697 
698 
700  """Representation of the HomematicIP passage detector delta counter."""
701 
702  @property
703  def native_value(self) -> int:
704  """Return the passage detector delta counter value."""
705  return self._device_device.leftRightCounterDelta
706 
707  @property
708  def extra_state_attributes(self) -> dict[str, Any]:
709  """Return the state attributes of the delta counter."""
710  state_attr = super().extra_state_attributes
711 
712  state_attr[ATTR_LEFT_COUNTER] = self._device_device.leftCounter
713  state_attr[ATTR_RIGHT_COUNTER] = self._device_device.rightCounter
714 
715  return state_attr
716 
717 
718 def _get_wind_direction(wind_direction_degree: float) -> str:
719  """Convert wind direction degree to named direction."""
720  if 11.25 <= wind_direction_degree < 33.75:
721  return "NNE"
722  if 33.75 <= wind_direction_degree < 56.25:
723  return "NE"
724  if 56.25 <= wind_direction_degree < 78.75:
725  return "ENE"
726  if 78.75 <= wind_direction_degree < 101.25:
727  return "E"
728  if 101.25 <= wind_direction_degree < 123.75:
729  return "ESE"
730  if 123.75 <= wind_direction_degree < 146.25:
731  return "SE"
732  if 146.25 <= wind_direction_degree < 168.75:
733  return "SSE"
734  if 168.75 <= wind_direction_degree < 191.25:
735  return "S"
736  if 191.25 <= wind_direction_degree < 213.75:
737  return "SSW"
738  if 213.75 <= wind_direction_degree < 236.25:
739  return "SW"
740  if 236.25 <= wind_direction_degree < 258.75:
741  return "WSW"
742  if 258.75 <= wind_direction_degree < 281.25:
743  return "W"
744  if 281.25 <= wind_direction_degree < 303.75:
745  return "WNW"
746  if 303.75 <= wind_direction_degree < 326.25:
747  return "NW"
748  if 326.25 <= wind_direction_degree < 348.75:
749  return "NNW"
750  return "N"
None __init__(self, HomematicipHAP hap, HomematicipGenericEntity device, str key, Callable[[FunctionalChannel], StateType] value_fn, Callable[[FunctionalChannel], str] type_fn)
Definition: sensor.py:528
None __init__(self, HomematicipHAP hap, device, channel, is_multi_channel=True)
Definition: sensor.py:225
def get_channels_from_device(Device device, FunctionalChannelType channel_type)
Definition: helpers.py:55
str _get_wind_direction(float wind_direction_degree)
Definition: sensor.py:718
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: sensor.py:100