Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Support for an Intergas heater via an InComfort/InTouch Lan2RF gateway."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 from typing import Any
7 
8 from incomfortclient import Heater as InComfortHeater
9 
11  SensorDeviceClass,
12  SensorEntity,
13  SensorEntityDescription,
14  SensorStateClass,
15 )
16 from homeassistant.const import UnitOfPressure, UnitOfTemperature
17 from homeassistant.core import HomeAssistant
18 from homeassistant.helpers.entity_platform import AddEntitiesCallback
19 from homeassistant.helpers.typing import StateType
20 
21 from . import InComfortConfigEntry
22 from .coordinator import InComfortDataCoordinator
23 from .entity import IncomfortBoilerEntity
24 
25 
26 @dataclass(frozen=True, kw_only=True)
28  """Describes Incomfort sensor entity."""
29 
30  value_key: str
31  extra_key: str | None = None
32 
33 
34 SENSOR_TYPES: tuple[IncomfortSensorEntityDescription, ...] = (
36  key="cv_pressure",
37  device_class=SensorDeviceClass.PRESSURE,
38  state_class=SensorStateClass.MEASUREMENT,
39  native_unit_of_measurement=UnitOfPressure.BAR,
40  value_key="pressure",
41  ),
43  key="cv_temp",
44  device_class=SensorDeviceClass.TEMPERATURE,
45  state_class=SensorStateClass.MEASUREMENT,
46  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
47  extra_key="is_pumping",
48  value_key="heater_temp",
49  ),
51  key="tap_temp",
52  translation_key="tap_temperature",
53  device_class=SensorDeviceClass.TEMPERATURE,
54  state_class=SensorStateClass.MEASUREMENT,
55  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
56  extra_key="is_tapping",
57  value_key="tap_temp",
58  ),
59 )
60 
61 
63  hass: HomeAssistant,
64  entry: InComfortConfigEntry,
65  async_add_entities: AddEntitiesCallback,
66 ) -> None:
67  """Set up InComfort/InTouch sensor entities."""
68  incomfort_coordinator = entry.runtime_data
69  heaters = incomfort_coordinator.data.heaters
71  IncomfortSensor(incomfort_coordinator, heater, description)
72  for heater in heaters
73  for description in SENSOR_TYPES
74  )
75 
76 
78  """Representation of an InComfort/InTouch sensor device."""
79 
80  entity_description: IncomfortSensorEntityDescription
81 
82  def __init__(
83  self,
84  coordinator: InComfortDataCoordinator,
85  heater: InComfortHeater,
86  description: IncomfortSensorEntityDescription,
87  ) -> None:
88  """Initialize the sensor."""
89  super().__init__(coordinator, heater)
90  self.entity_descriptionentity_description = description
91  self._attr_unique_id_attr_unique_id = f"{heater.serial_no}_{description.key}"
92 
93  @property
94  def native_value(self) -> StateType:
95  """Return the state of the sensor."""
96  return self._heater_heater.status[self.entity_descriptionentity_description.value_key]
97 
98  @property
99  def extra_state_attributes(self) -> dict[str, Any] | None:
100  """Return the device state attributes."""
101  if (extra_key := self.entity_descriptionentity_description.extra_key) is None:
102  return None
103  return {extra_key: self._heater_heater.status[extra_key]}
None __init__(self, InComfortDataCoordinator coordinator, InComfortHeater heater, IncomfortSensorEntityDescription description)
Definition: sensor.py:87
None async_setup_entry(HomeAssistant hass, InComfortConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: sensor.py:66