diff --git a/homeassistant/components/airzone/entity.py b/homeassistant/components/airzone/entity.py index 021aaa3535c..267cd210ff0 100644 --- a/homeassistant/components/airzone/entity.py +++ b/homeassistant/components/airzone/entity.py @@ -10,6 +10,7 @@ from aioairzone.const import ( AZD_AVAILABLE, AZD_FIRMWARE, AZD_FULL_NAME, + AZD_HOT_WATER, AZD_ID, AZD_MAC, AZD_MODEL, @@ -81,6 +82,31 @@ class AirzoneSystemEntity(AirzoneEntity): return value +class AirzoneHotWaterEntity(AirzoneEntity): + """Define an Airzone Hot Water entity.""" + + def __init__( + self, + coordinator: AirzoneUpdateCoordinator, + entry: ConfigEntry, + ) -> None: + """Initialize.""" + super().__init__(coordinator) + + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, f"{entry.entry_id}_dhw")}, + manufacturer=MANUFACTURER, + model="DHW", + name=self.get_airzone_value(AZD_NAME), + via_device=(DOMAIN, f"{entry.entry_id}_ws"), + ) + self._attr_unique_id = entry.unique_id or entry.entry_id + + def get_airzone_value(self, key: str) -> Any: + """Return DHW value by key.""" + return self.coordinator.data[AZD_HOT_WATER].get(key) + + class AirzoneWebServerEntity(AirzoneEntity): """Define an Airzone WebServer entity.""" diff --git a/homeassistant/components/airzone/sensor.py b/homeassistant/components/airzone/sensor.py index d90fdf93607..1dd67294aff 100644 --- a/homeassistant/components/airzone/sensor.py +++ b/homeassistant/components/airzone/sensor.py @@ -4,6 +4,7 @@ from __future__ import annotations from typing import Any, Final from aioairzone.const import ( + AZD_HOT_WATER, AZD_HUMIDITY, AZD_NAME, AZD_TEMP, @@ -31,7 +32,21 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN, TEMP_UNIT_LIB_TO_HASS from .coordinator import AirzoneUpdateCoordinator -from .entity import AirzoneEntity, AirzoneWebServerEntity, AirzoneZoneEntity +from .entity import ( + AirzoneEntity, + AirzoneHotWaterEntity, + AirzoneWebServerEntity, + AirzoneZoneEntity, +) + +HOT_WATER_SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = ( + SensorEntityDescription( + device_class=SensorDeviceClass.TEMPERATURE, + key=AZD_TEMP, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, + state_class=SensorStateClass.MEASUREMENT, + ), +) WEBSERVER_SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = ( SensorEntityDescription( @@ -71,6 +86,18 @@ async def async_setup_entry( sensors: list[AirzoneSensor] = [] + if AZD_HOT_WATER in coordinator.data: + dhw_data = coordinator.data[AZD_HOT_WATER] + for description in HOT_WATER_SENSOR_TYPES: + if description.key in dhw_data: + sensors.append( + AirzoneHotWaterSensor( + coordinator, + description, + entry, + ) + ) + if AZD_WEBSERVER in coordinator.data: ws_data = coordinator.data[AZD_WEBSERVER] for description in WEBSERVER_SENSOR_TYPES: @@ -114,6 +141,30 @@ class AirzoneSensor(AirzoneEntity, SensorEntity): self._attr_native_value = self.get_airzone_value(self.entity_description.key) +class AirzoneHotWaterSensor(AirzoneHotWaterEntity, AirzoneSensor): + """Define an Airzone Hot Water sensor.""" + + _attr_has_entity_name = True + + def __init__( + self, + coordinator: AirzoneUpdateCoordinator, + description: SensorEntityDescription, + entry: ConfigEntry, + ) -> None: + """Initialize.""" + super().__init__(coordinator, entry) + + self._attr_unique_id = f"{self._attr_unique_id}_dhw_{description.key}" + self.entity_description = description + + self._attr_native_unit_of_measurement = TEMP_UNIT_LIB_TO_HASS.get( + self.get_airzone_value(AZD_TEMP_UNIT) + ) + + self._async_update_attrs() + + class AirzoneWebServerSensor(AirzoneWebServerEntity, AirzoneSensor): """Define an Airzone WebServer sensor.""" diff --git a/tests/components/airzone/test_sensor.py b/tests/components/airzone/test_sensor.py index cce8a452a15..4de1cae7555 100644 --- a/tests/components/airzone/test_sensor.py +++ b/tests/components/airzone/test_sensor.py @@ -28,6 +28,10 @@ async def test_airzone_create_sensors( await async_init_integration(hass) + # Hot Water + state = hass.states.get("sensor.airzone_dhw_temperature") + assert state.state == "43" + # WebServer state = hass.states.get("sensor.webserver_rssi") assert state.state == "-42"