Add Airzone Cloud Aidoo binary sensors (#95607)
airzone_cloud: add Aidoo binary sensors Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>pull/97175/head
parent
9f9602e8a7
commit
d1e96a356a
|
@ -4,7 +4,14 @@ from __future__ import annotations
|
|||
from dataclasses import dataclass
|
||||
from typing import Any, Final
|
||||
|
||||
from aioairzone_cloud.const import AZD_ACTIVE, AZD_PROBLEMS, AZD_WARNINGS, AZD_ZONES
|
||||
from aioairzone_cloud.const import (
|
||||
AZD_ACTIVE,
|
||||
AZD_AIDOOS,
|
||||
AZD_ERRORS,
|
||||
AZD_PROBLEMS,
|
||||
AZD_WARNINGS,
|
||||
AZD_ZONES,
|
||||
)
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
|
@ -18,7 +25,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import AirzoneUpdateCoordinator
|
||||
from .entity import AirzoneEntity, AirzoneZoneEntity
|
||||
from .entity import AirzoneAidooEntity, AirzoneEntity, AirzoneZoneEntity
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -28,6 +35,22 @@ class AirzoneBinarySensorEntityDescription(BinarySensorEntityDescription):
|
|||
attributes: dict[str, str] | None = None
|
||||
|
||||
|
||||
AIDOO_BINARY_SENSOR_TYPES: Final[tuple[AirzoneBinarySensorEntityDescription, ...]] = (
|
||||
AirzoneBinarySensorEntityDescription(
|
||||
device_class=BinarySensorDeviceClass.RUNNING,
|
||||
key=AZD_ACTIVE,
|
||||
),
|
||||
AirzoneBinarySensorEntityDescription(
|
||||
attributes={
|
||||
"errors": AZD_ERRORS,
|
||||
"warnings": AZD_WARNINGS,
|
||||
},
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
key=AZD_PROBLEMS,
|
||||
),
|
||||
)
|
||||
|
||||
ZONE_BINARY_SENSOR_TYPES: Final[tuple[AirzoneBinarySensorEntityDescription, ...]] = (
|
||||
AirzoneBinarySensorEntityDescription(
|
||||
device_class=BinarySensorDeviceClass.RUNNING,
|
||||
|
@ -52,6 +75,18 @@ async def async_setup_entry(
|
|||
|
||||
binary_sensors: list[AirzoneBinarySensor] = []
|
||||
|
||||
for aidoo_id, aidoo_data in coordinator.data.get(AZD_AIDOOS, {}).items():
|
||||
for description in AIDOO_BINARY_SENSOR_TYPES:
|
||||
if description.key in aidoo_data:
|
||||
binary_sensors.append(
|
||||
AirzoneAidooBinarySensor(
|
||||
coordinator,
|
||||
description,
|
||||
aidoo_id,
|
||||
aidoo_data,
|
||||
)
|
||||
)
|
||||
|
||||
for zone_id, zone_data in coordinator.data.get(AZD_ZONES, {}).items():
|
||||
for description in ZONE_BINARY_SENSOR_TYPES:
|
||||
if description.key in zone_data:
|
||||
|
@ -89,6 +124,27 @@ class AirzoneBinarySensor(AirzoneEntity, BinarySensorEntity):
|
|||
}
|
||||
|
||||
|
||||
class AirzoneAidooBinarySensor(AirzoneAidooEntity, AirzoneBinarySensor):
|
||||
"""Define an Airzone Cloud Aidoo binary sensor."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: AirzoneUpdateCoordinator,
|
||||
description: AirzoneBinarySensorEntityDescription,
|
||||
aidoo_id: str,
|
||||
aidoo_data: dict[str, Any],
|
||||
) -> None:
|
||||
"""Initialize."""
|
||||
super().__init__(coordinator, aidoo_id, aidoo_data)
|
||||
|
||||
self._attr_unique_id = f"{aidoo_id}_{description.key}"
|
||||
self.entity_description = description
|
||||
|
||||
self._async_update_attrs()
|
||||
|
||||
|
||||
class AirzoneZoneBinarySensor(AirzoneZoneEntity, AirzoneBinarySensor):
|
||||
"""Define an Airzone Cloud Zone binary sensor."""
|
||||
|
||||
|
|
|
@ -11,6 +11,15 @@ async def test_airzone_create_binary_sensors(hass: HomeAssistant) -> None:
|
|||
|
||||
await async_init_integration(hass)
|
||||
|
||||
# Aidoo
|
||||
state = hass.states.get("binary_sensor.bron_problem")
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get("errors") is None
|
||||
assert state.attributes.get("warnings") is None
|
||||
|
||||
state = hass.states.get("binary_sensor.bron_running")
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# Zones
|
||||
state = hass.states.get("binary_sensor.dormitorio_problem")
|
||||
assert state.state == STATE_OFF
|
||||
|
|
|
@ -163,6 +163,7 @@ def mock_get_device_status(device: Device) -> dict[str, Any]:
|
|||
|
||||
if device.get_id() == "aidoo1":
|
||||
return {
|
||||
API_ACTIVE: False,
|
||||
API_ERRORS: [],
|
||||
API_IS_CONNECTED: True,
|
||||
API_WS_CONNECTED: True,
|
||||
|
|
Loading…
Reference in New Issue