Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """The Aseko Pool Live integration."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 import logging
7 
8 from aioaseko import Aseko, Unit
9 
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
13 
14 from .const import DOMAIN
15 
16 _LOGGER = logging.getLogger(__name__)
17 
18 type AsekoConfigEntry = ConfigEntry[AsekoDataUpdateCoordinator]
19 
20 
22  """Class to manage fetching Aseko unit data from single endpoint."""
23 
24  def __init__(self, hass: HomeAssistant, aseko: Aseko) -> None:
25  """Initialize global Aseko unit data updater."""
26  self._aseko_aseko = aseko
27 
28  super().__init__(
29  hass,
30  _LOGGER,
31  name=DOMAIN,
32  update_interval=timedelta(minutes=2),
33  )
34 
35  async def _async_update_data(self) -> dict[str, Unit]:
36  """Fetch unit data."""
37  units = await self._aseko_aseko.get_units()
38  return {unit.serial_number: unit for unit in units}