Skip to content

Commit

Permalink
Add Domestic Hot Water support
Browse files Browse the repository at this point in the history
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
  • Loading branch information
Noltari committed Apr 5, 2024
1 parent 6b880b7 commit 3e8feb5
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 1 deletion.
58 changes: 58 additions & 0 deletions aioairzone_cloud/cloudapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
from .const import (
API_AUTH_LOGIN,
API_AUTH_REFRESH_TOKEN,
API_AZ_ACS,
API_AZ_AIDOO,
API_AZ_AIDOO_ACS,
API_AZ_AIDOO_PRO,
API_AZ_SYSTEM,
API_AZ_ZONE,
Expand Down Expand Up @@ -45,6 +47,7 @@
API_WS_ID,
AZD_AIDOOS,
AZD_GROUPS,
AZD_HOT_WATERS,
AZD_INSTALLATIONS,
AZD_SYSTEMS,
AZD_WEBSERVERS,
Expand All @@ -70,6 +73,7 @@
TooManyRequests,
)
from .group import Group
from .hotwater import HotWater
from .installation import Installation
from .system import System
from .token import AirzoneCloudToken
Expand Down Expand Up @@ -104,6 +108,7 @@ def __init__(
self.callback_function = None
self.callback_lock = Lock()
self.devices: dict[str, Device] = {}
self.dhws: dict[str, HotWater] = {}
self.groups: dict[str, Group] = {}
self.installations: dict[str, Installation] = {}
self.options = options
Expand Down Expand Up @@ -400,6 +405,12 @@ async def api_set_device_id_params(
if device is not None:
await self.api_set_device_params(device, params)

async def api_set_dhw_id_params(self, dhw_id: str, params: dict[str, Any]) -> None:
"""Set dhw parameters."""
dhw = self.get_dhw_id(dhw_id)
if dhw is not None:
await self.api_set_device_params(dhw, params)

async def api_set_group_id_params(
self, group_id: str, params: dict[str, Any]
) -> None:
Expand Down Expand Up @@ -487,6 +498,12 @@ def data(self) -> dict[str, Any]:
aidoos[key] = aidoo.data()
data[AZD_AIDOOS] = aidoos

if len(self.dhws) > 0:
dhws: dict[str, Any] = {}
for key, dhw in self.dhws.items():
dhws[key] = dhw.data()
data[AZD_HOT_WATERS] = dhws

if len(self.groups) > 0:
groups: dict[str, Any] = {}
for key, group in self.groups.items():
Expand Down Expand Up @@ -530,6 +547,11 @@ def add_device(self, device: Device) -> None:
if dev_id not in self.devices:
self.devices[dev_id] = device

def add_dhw(self, dhw: HotWater) -> None:
"""Add Airzone Cloud Domestic Hot Water."""
self.dhws[dhw.get_id()] = dhw
self.add_device(dhw)

def add_system(self, system: System) -> None:
"""Add Airzone Cloud System."""
self.systems[system.get_id()] = system
Expand All @@ -550,6 +572,10 @@ def get_device_id(self, dev_id: str | None) -> Device | None:
return self.devices.get(dev_id)
return None

def get_dhw_id(self, dhw_id: str) -> HotWater | None:
"""Return Airzone Cloud DHW by ID."""
return self.dhws.get(dhw_id)

def get_group_id(self, group_id: str) -> Group | None:
"""Return Airzone Cloud Group by ID."""
return self.groups.get(group_id)
Expand Down Expand Up @@ -639,6 +665,23 @@ async def update_aidoos(self) -> None:

await asyncio.gather(*tasks)

async def update_dhw(self, dhw: HotWater) -> None:
"""Update Airzone Cloud DHW from API."""
device_data = await self.api_get_device_status(dhw)

update = EntityUpdate(UpdateType.API_FULL, device_data)

await dhw.update(update)

async def update_dhws(self) -> None:
"""Update all Airzone Cloud DHWs."""
tasks = []

for dhw in self.dhws.values():
tasks += [self.update_dhw(dhw)]

await asyncio.gather(*tasks)

def connect_installation_websockets(self, inst_id: str) -> None:
"""Connect installation WebSockets."""
if not self.options.websockets:
Expand Down Expand Up @@ -680,6 +723,13 @@ async def update_installation(self, inst: Installation) -> None:
self.add_aidoo(aidoo)
group.add_aidoo(aidoo)
inst.add_aidoo(aidoo)
elif device_type in [API_AZ_ACS, API_AZ_AIDOO_ACS]:
if self.get_dhw_id(device_id) is None:
dhw = HotWater(inst_id, device_data[API_WS_ID], device_data)
if HotWater is not None:
self.add_dhw(dhw)
group.add_dhw(dhw)
inst.add_dhw(dhw)

self.connect_installation_websockets(inst_id)

Expand Down Expand Up @@ -767,6 +817,13 @@ async def update_webserver(self, ws: WebServer, devices: bool) -> None:
self.add_aidoo(aidoo)
if inst is not None:
inst.add_aidoo(aidoo)
elif device_type in [API_AZ_ACS, API_AZ_AIDOO_ACS]:
if self.get_dhw_id(device_id) is None:
dhw = HotWater(ws.get_installation(), ws_id, device_data)
if dhw is not None:
self.add_dhw(dhw)
if inst is not None:
inst.add_dhw(dhw)

async def update_webserver_id(self, ws_id: str, devices: bool) -> None:
"""Update Airzone Cloud WebServer by ID."""
Expand Down Expand Up @@ -815,6 +872,7 @@ async def _update_polling(self) -> None:
self.update_webservers(False),
self.update_systems_zones(),
self.update_aidoos(),
self.update_dhws(),
]

await asyncio.gather(*tasks)
Expand Down
12 changes: 12 additions & 0 deletions aioairzone_cloud/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@
API_PASSWORD: Final[str] = "password"
API_PIN: Final[str] = "pin"
API_POWER: Final[str] = "power"
API_POWERFUL_MODE: Final[str] = "powerful_mode"
API_RANGE_MAX_AIR: Final[str] = "range_air_max"
API_RANGE_MIN_AIR: Final[str] = "range_air_min"
API_RANGE_SP_MAX_ACS: Final[str] = "range_sp_acs_max"
API_RANGE_SP_MAX_AUTO_AIR: Final[str] = "range_sp_auto_air_max"
API_RANGE_SP_MAX_COOL_AIR: Final[str] = "range_sp_cool_air_max"
API_RANGE_SP_MAX_DRY_AIR: Final[str] = "range_sp_dry_air_max"
API_RANGE_SP_MAX_EMERHEAT_AIR: Final[str] = "range_sp_emerheat_air_max"
API_RANGE_SP_MAX_HOT_AIR: Final[str] = "range_sp_hot_air_max"
API_RANGE_SP_MAX_STOP_AIR: Final[str] = "range_sp_stop_air_max"
API_RANGE_SP_MAX_VENT_AIR: Final[str] = "range_sp_vent_air_max"
API_RANGE_SP_MIN_ACS: Final[str] = "range_sp_acs_min"
API_RANGE_SP_MIN_AUTO_AIR: Final[str] = "range_sp_auto_air_min"
API_RANGE_SP_MIN_COOL_AIR: Final[str] = "range_sp_cool_air_min"
API_RANGE_SP_MIN_DRY_AIR: Final[str] = "range_sp_dry_air_min"
Expand Down Expand Up @@ -86,6 +89,8 @@
API_STATUS: Final[str] = "status"
API_STEP: Final[str] = "step"
API_SYSTEM_NUMBER: Final[str] = "system_number"
API_TANK_TEMP: Final[str] = "tank_temp"
API_TT_UNITS: Final[str] = "tt_units"
API_TIMER: Final[str] = "timer"
API_TOKEN: Final[str] = "token"
API_TYPE: Final[str] = "type"
Expand All @@ -112,11 +117,14 @@
"bad": 301,
}
API_AZ_AIDOO: Final[str] = "aidoo"
API_AZ_AIDOO_ACS: Final[str] = "aidoo_acs"
API_AZ_AIDOO_PRO: Final[str] = "aidoo_it"
API_AZ_ACS: Final[str] = "az_acs"
API_AZ_SYSTEM: Final[str] = "az_system"
API_AZ_ZONE: Final[str] = "az_zone"

API_DEFAULT_TEMP_STEP: Final[float] = 0.5
API_DEFAULT_TEMP_STEP_ACS: Final[int] = 1

AZD_ACTION: Final[str] = "action"
AZD_ACTIVE: Final[str] = "active"
Expand All @@ -138,10 +146,12 @@
AZD_FIRMWARE: Final[str] = "firmware"
AZD_GROUPS: Final[str] = "groups"
AZD_HUMIDITY: Final[str] = "humidity"
AZD_HOT_WATERS: Final[str] = "hot-water"
AZD_ID: Final[str] = "id"
AZD_INSTALLATION: Final[str] = "installation"
AZD_INSTALLATIONS: Final[str] = "installations"
AZD_IS_CONNECTED: Final[str] = "is-connected"
AZD_MACHINE_READY: Final[str] = "machineready"
AZD_MASTER: Final[str] = "master"
AZD_MODE: Final[str] = "mode"
AZD_MODE_AUTO: Final[str] = "mode-auto"
Expand All @@ -150,7 +160,9 @@
AZD_NUM_DEVICES: Final[str] = "num-devices"
AZD_NUM_GROUPS: Final[str] = "num-groups"
AZD_POWER: Final[str] = "power"
AZD_POWER_MODE: Final[str] = "power-mode"
AZD_PROBLEMS: Final[str] = "problems"
AZD_RAD_ACTIVE: Final[str] = "rad_active"
AZD_SPEED: Final[str] = "speed"
AZD_SPEEDS: Final[str] = "speeds"
AZD_SPEED_TYPE: Final[str] = "speed-type"
Expand Down
5 changes: 4 additions & 1 deletion aioairzone_cloud/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def data(self) -> dict[str, Any]:
AZD_ID: self.get_id(),
AZD_INSTALLATION: self.get_installation(),
AZD_IS_CONNECTED: self.get_is_connected(),
AZD_MODE: self.get_mode(),
AZD_NAME: self.get_name(),
AZD_PROBLEMS: self.get_problems(),
AZD_WEBSERVER: self.get_webserver(),
Expand Down Expand Up @@ -134,6 +133,10 @@ def data(self) -> dict[str, Any]:
if len(errors) > 0:
data[AZD_ERRORS] = errors

mode = self.get_mode()
if mode is not None:
data[AZD_MODE] = mode

mode_auto = self.get_mode_auto()
if mode_auto is not None:
data[AZD_MODE_AUTO] = mode_auto
Expand Down
11 changes: 11 additions & 0 deletions aioairzone_cloud/device_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
AZD_ACTIVE,
AZD_AIDOOS,
AZD_AVAILABLE,
AZD_HOT_WATERS,
AZD_HUMIDITY,
AZD_ID,
AZD_MODE,
Expand All @@ -31,6 +32,7 @@
AZD_TEMP_STEP,
AZD_ZONES,
)
from .hotwater import HotWater
from .system import System
from .zone import Zone

Expand All @@ -45,6 +47,7 @@ def __init__(self) -> None:
"""Airzone Cloud DeviceGroup init."""

self.aidoos: dict[str, Aidoo] = {}
self.dhws: dict[str, HotWater] = {}
self.systems: dict[str, System] = {}
self.zones: dict[str, Zone] = {}

Expand All @@ -54,6 +57,8 @@ def data(self) -> dict[str, Any]:

if len(self.aidoos) > 0:
data[AZD_AIDOOS] = list(self.aidoos)
if len(self.dhws) > 0:
data[AZD_HOT_WATERS] = list(self.dhws)
if len(self.systems) > 0:
data[AZD_SYSTEMS] = list(self.systems)
if len(self.zones) > 0:
Expand Down Expand Up @@ -135,6 +140,12 @@ def add_aidoo(self, aidoo: Aidoo) -> None:
if aidoo_id not in self.aidoos:
self.aidoos[aidoo_id] = aidoo

def add_dhw(self, dhw: HotWater) -> None:
"""Add DHW to DeviceGroup."""
dhw_id = dhw.get_id()
if dhw_id not in self.dhws:
self.dhws[dhw_id] = dhw

def add_system(self, system: System) -> None:
"""Add System to DeviceGroup."""
system_id = system.get_id()
Expand Down
Loading

0 comments on commit 3e8feb5

Please sign in to comment.