mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Add hot water sensor support to Airzone (#98500)
* airzone: sensors: add hot water support Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> * airzone: sensor: dhw: enable _attr_has_entity_name Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> * Add requested changes Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> --------- Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
This commit is contained in:
parent
af915f1425
commit
99b5c4932f
@ -10,6 +10,7 @@ from aioairzone.const import (
|
|||||||
AZD_AVAILABLE,
|
AZD_AVAILABLE,
|
||||||
AZD_FIRMWARE,
|
AZD_FIRMWARE,
|
||||||
AZD_FULL_NAME,
|
AZD_FULL_NAME,
|
||||||
|
AZD_HOT_WATER,
|
||||||
AZD_ID,
|
AZD_ID,
|
||||||
AZD_MAC,
|
AZD_MAC,
|
||||||
AZD_MODEL,
|
AZD_MODEL,
|
||||||
@ -81,6 +82,31 @@ class AirzoneSystemEntity(AirzoneEntity):
|
|||||||
return value
|
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):
|
class AirzoneWebServerEntity(AirzoneEntity):
|
||||||
"""Define an Airzone WebServer entity."""
|
"""Define an Airzone WebServer entity."""
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
from typing import Any, Final
|
from typing import Any, Final
|
||||||
|
|
||||||
from aioairzone.const import (
|
from aioairzone.const import (
|
||||||
|
AZD_HOT_WATER,
|
||||||
AZD_HUMIDITY,
|
AZD_HUMIDITY,
|
||||||
AZD_NAME,
|
AZD_NAME,
|
||||||
AZD_TEMP,
|
AZD_TEMP,
|
||||||
@ -31,7 +32,21 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
|
|
||||||
from .const import DOMAIN, TEMP_UNIT_LIB_TO_HASS
|
from .const import DOMAIN, TEMP_UNIT_LIB_TO_HASS
|
||||||
from .coordinator import AirzoneUpdateCoordinator
|
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, ...]] = (
|
WEBSERVER_SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
@ -71,6 +86,18 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
sensors: list[AirzoneSensor] = []
|
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:
|
if AZD_WEBSERVER in coordinator.data:
|
||||||
ws_data = coordinator.data[AZD_WEBSERVER]
|
ws_data = coordinator.data[AZD_WEBSERVER]
|
||||||
for description in WEBSERVER_SENSOR_TYPES:
|
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)
|
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):
|
class AirzoneWebServerSensor(AirzoneWebServerEntity, AirzoneSensor):
|
||||||
"""Define an Airzone WebServer sensor."""
|
"""Define an Airzone WebServer sensor."""
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ async def test_airzone_create_sensors(
|
|||||||
|
|
||||||
await async_init_integration(hass)
|
await async_init_integration(hass)
|
||||||
|
|
||||||
|
# Hot Water
|
||||||
|
state = hass.states.get("sensor.airzone_dhw_temperature")
|
||||||
|
assert state.state == "43"
|
||||||
|
|
||||||
# WebServer
|
# WebServer
|
||||||
state = hass.states.get("sensor.webserver_rssi")
|
state = hass.states.get("sensor.webserver_rssi")
|
||||||
assert state.state == "-42"
|
assert state.state == "-42"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user