1 """Support for the Airzone sensors."""
3 from __future__
import annotations
5 from typing
import Any, Final
7 from aioairzone.const
import (
20 SensorEntityDescription,
26 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
33 from .
import AirzoneConfigEntry
34 from .const
import TEMP_UNIT_LIB_TO_HASS
35 from .coordinator
import AirzoneUpdateCoordinator
38 AirzoneHotWaterEntity,
39 AirzoneWebServerEntity,
43 HOT_WATER_SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = (
45 device_class=SensorDeviceClass.TEMPERATURE,
47 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
48 state_class=SensorStateClass.MEASUREMENT,
52 WEBSERVER_SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = (
54 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
55 entity_category=EntityCategory.DIAGNOSTIC,
56 entity_registry_enabled_default=
False,
58 translation_key=
"rssi",
59 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
60 state_class=SensorStateClass.MEASUREMENT,
64 ZONE_SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = (
66 device_class=SensorDeviceClass.TEMPERATURE,
68 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
69 state_class=SensorStateClass.MEASUREMENT,
72 device_class=SensorDeviceClass.HUMIDITY,
74 native_unit_of_measurement=PERCENTAGE,
75 state_class=SensorStateClass.MEASUREMENT,
82 entry: AirzoneConfigEntry,
83 async_add_entities: AddEntitiesCallback,
85 """Add Airzone sensors from a config_entry."""
86 coordinator = entry.runtime_data
88 added_zones: set[str] = set()
90 def _async_entity_listener() -> None:
91 """Handle additions of sensors."""
93 entities: list[AirzoneSensor] = []
95 zones_data = coordinator.data.get(AZD_ZONES, {})
96 received_zones = set(zones_data)
97 new_zones = received_zones - added_zones
105 zones_data.get(system_zone_id),
107 for system_zone_id
in new_zones
108 for description
in ZONE_SENSOR_TYPES
109 if description.key
in zones_data.get(system_zone_id)
111 added_zones.update(new_zones)
115 entities: list[AirzoneSensor] = []
117 if AZD_HOT_WATER
in coordinator.data:
124 for description
in HOT_WATER_SENSOR_TYPES
125 if description.key
in coordinator.data[AZD_HOT_WATER]
128 if AZD_WEBSERVER
in coordinator.data:
135 for description
in WEBSERVER_SENSOR_TYPES
136 if description.key
in coordinator.data[AZD_WEBSERVER]
141 entry.async_on_unload(coordinator.async_add_listener(_async_entity_listener))
142 _async_entity_listener()
146 """Define an Airzone sensor."""
150 """Update attributes when the coordinator updates."""
156 """Update sensor attributes."""
161 """Define an Airzone Hot Water sensor."""
165 coordinator: AirzoneUpdateCoordinator,
166 description: SensorEntityDescription,
170 super().
__init__(coordinator, entry)
183 """Define an Airzone WebServer sensor."""
187 coordinator: AirzoneUpdateCoordinator,
188 description: SensorEntityDescription,
192 super().
__init__(coordinator, entry)
199 """Define an Airzone Zone sensor."""
203 coordinator: AirzoneUpdateCoordinator,
204 description: SensorEntityDescription,
207 zone_data: dict[str, Any],
210 super().
__init__(coordinator, entry, system_zone_id, zone_data)
213 f
"{self._attr_unique_id}_{system_zone_id}_{description.key}"
217 if description.key == AZD_TEMP:
Any get_airzone_value(self, str key)
Any get_airzone_value(self, str key)
Any get_airzone_value(self, str key)
_attr_native_unit_of_measurement
None __init__(self, AirzoneUpdateCoordinator coordinator, SensorEntityDescription description, ConfigEntry entry)
None _handle_coordinator_update(self)
None _async_update_attrs(self)
None __init__(self, AirzoneUpdateCoordinator coordinator, SensorEntityDescription description, ConfigEntry entry)
None __init__(self, AirzoneUpdateCoordinator coordinator, SensorEntityDescription description, ConfigEntry entry, str system_zone_id, dict[str, Any] zone_data)
_attr_native_unit_of_measurement
None async_setup_entry(HomeAssistant hass, AirzoneConfigEntry entry, AddEntitiesCallback async_add_entities)