2020-10-18 20:30:53 +02:00
|
|
|
"""Switch platform for Advantage Air integration."""
|
2022-08-18 15:56:52 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2023-04-17 00:27:37 +02:00
|
|
|
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
2021-12-24 13:45:42 +01:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-10-18 20:30:53 +02:00
|
|
|
|
|
|
|
from .const import (
|
|
|
|
ADVANTAGE_AIR_STATE_OFF,
|
|
|
|
ADVANTAGE_AIR_STATE_ON,
|
|
|
|
DOMAIN as ADVANTAGE_AIR_DOMAIN,
|
|
|
|
)
|
2023-04-17 00:27:37 +02:00
|
|
|
from .entity import AdvantageAirAcEntity, AdvantageAirThingEntity
|
2020-10-18 20:30:53 +02:00
|
|
|
|
|
|
|
|
2021-12-24 13:45:42 +01:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2022-07-17 14:00:01 +02:00
|
|
|
"""Set up AdvantageAir switch platform."""
|
2020-10-18 20:30:53 +02:00
|
|
|
|
|
|
|
instance = hass.data[ADVANTAGE_AIR_DOMAIN][config_entry.entry_id]
|
|
|
|
|
2022-09-18 21:27:09 +02:00
|
|
|
entities: list[SwitchEntity] = []
|
|
|
|
if aircons := instance["coordinator"].data.get("aircons"):
|
|
|
|
for ac_key, ac_device in aircons.items():
|
|
|
|
if ac_device["info"]["freshAirStatus"] != "none":
|
|
|
|
entities.append(AdvantageAirFreshAir(instance, ac_key))
|
2023-04-17 00:27:37 +02:00
|
|
|
if things := instance["coordinator"].data.get("myThings"):
|
|
|
|
for thing in things["things"].values():
|
|
|
|
if thing["channelDipState"] == 8: # 8 = Other relay
|
|
|
|
entities.append(AdvantageAirRelay(instance, thing))
|
2020-10-18 20:30:53 +02:00
|
|
|
async_add_entities(entities)
|
|
|
|
|
|
|
|
|
2022-07-25 12:20:15 +02:00
|
|
|
class AdvantageAirFreshAir(AdvantageAirAcEntity, SwitchEntity):
|
2020-10-18 20:30:53 +02:00
|
|
|
"""Representation of Advantage Air fresh air control."""
|
|
|
|
|
2021-07-24 13:00:41 +02:00
|
|
|
_attr_icon = "mdi:air-filter"
|
2022-07-18 23:02:58 +02:00
|
|
|
_attr_name = "Fresh air"
|
2023-04-17 00:27:37 +02:00
|
|
|
_attr_device_class = SwitchDeviceClass.SWITCH
|
2021-07-24 13:00:41 +02:00
|
|
|
|
2022-09-18 21:27:09 +02:00
|
|
|
def __init__(self, instance: dict[str, Any], ac_key: str) -> None:
|
2021-07-24 13:00:41 +02:00
|
|
|
"""Initialize an Advantage Air fresh air control."""
|
|
|
|
super().__init__(instance, ac_key)
|
2022-07-25 12:20:15 +02:00
|
|
|
self._attr_unique_id += "-freshair"
|
2020-10-18 20:30:53 +02:00
|
|
|
|
|
|
|
@property
|
2022-09-18 21:27:09 +02:00
|
|
|
def is_on(self) -> bool:
|
2020-10-18 20:30:53 +02:00
|
|
|
"""Return the fresh air status."""
|
|
|
|
return self._ac["freshAirStatus"] == ADVANTAGE_AIR_STATE_ON
|
|
|
|
|
2022-08-18 15:56:52 +02:00
|
|
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
2020-10-18 20:30:53 +02:00
|
|
|
"""Turn fresh air on."""
|
2022-09-18 21:27:09 +02:00
|
|
|
await self.aircon(
|
2020-10-18 20:30:53 +02:00
|
|
|
{self.ac_key: {"info": {"freshAirStatus": ADVANTAGE_AIR_STATE_ON}}}
|
|
|
|
)
|
|
|
|
|
2022-08-18 15:56:52 +02:00
|
|
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
2020-10-18 20:30:53 +02:00
|
|
|
"""Turn fresh air off."""
|
2022-09-18 21:27:09 +02:00
|
|
|
await self.aircon(
|
2020-10-18 20:30:53 +02:00
|
|
|
{self.ac_key: {"info": {"freshAirStatus": ADVANTAGE_AIR_STATE_OFF}}}
|
|
|
|
)
|
2023-04-17 00:27:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AdvantageAirRelay(AdvantageAirThingEntity, SwitchEntity):
|
|
|
|
"""Representation of Advantage Air Thing."""
|
|
|
|
|
|
|
|
_attr_device_class = SwitchDeviceClass.SWITCH
|