2022-03-08 21:28:39 +00:00
|
|
|
"""The Airzone integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from datetime import timedelta
|
|
|
|
import logging
|
2022-05-10 14:49:40 +00:00
|
|
|
from typing import Any
|
2022-03-08 21:28:39 +00:00
|
|
|
|
2022-04-13 17:12:21 +00:00
|
|
|
from aioairzone.exceptions import AirzoneError
|
2022-03-28 23:05:47 +00:00
|
|
|
from aioairzone.localapi import AirzoneLocalApi
|
2022-03-08 21:28:39 +00:00
|
|
|
import async_timeout
|
|
|
|
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
|
|
|
|
|
|
|
from .const import AIOAIRZONE_DEVICE_TIMEOUT_SEC, DOMAIN
|
|
|
|
|
|
|
|
SCAN_INTERVAL = timedelta(seconds=60)
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-05-09 17:56:59 +00:00
|
|
|
class AirzoneUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
2022-03-08 21:28:39 +00:00
|
|
|
"""Class to manage fetching data from the Airzone device."""
|
|
|
|
|
|
|
|
def __init__(self, hass: HomeAssistant, airzone: AirzoneLocalApi) -> None:
|
|
|
|
"""Initialize."""
|
|
|
|
self.airzone = airzone
|
|
|
|
|
|
|
|
super().__init__(
|
|
|
|
hass,
|
|
|
|
_LOGGER,
|
|
|
|
name=DOMAIN,
|
|
|
|
update_interval=SCAN_INTERVAL,
|
|
|
|
)
|
|
|
|
|
2022-05-10 08:00:38 +00:00
|
|
|
async def _async_update_data(self) -> dict[str, Any]:
|
2022-03-08 21:28:39 +00:00
|
|
|
"""Update data via library."""
|
|
|
|
async with async_timeout.timeout(AIOAIRZONE_DEVICE_TIMEOUT_SEC):
|
|
|
|
try:
|
2022-04-19 15:03:13 +00:00
|
|
|
await self.airzone.update()
|
2022-04-13 17:12:21 +00:00
|
|
|
except AirzoneError as error:
|
2022-03-08 21:28:39 +00:00
|
|
|
raise UpdateFailed(error) from error
|
2022-05-10 14:49:40 +00:00
|
|
|
return self.airzone.data()
|