Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Coordinator for Vallox ventilation units."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from vallox_websocket_api import MetricData, Vallox, ValloxApiException
8 
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
11 
12 from .const import STATE_SCAN_INTERVAL
13 
14 _LOGGER = logging.getLogger(__name__)
15 
16 
18  """The DataUpdateCoordinator for Vallox."""
19 
20  def __init__(
21  self,
22  hass: HomeAssistant,
23  name: str,
24  client: Vallox,
25  ) -> None:
26  """Initialize Vallox data coordinator."""
27  super().__init__(
28  hass,
29  _LOGGER,
30  name=f"{name} DataUpdateCoordinator",
31  update_interval=STATE_SCAN_INTERVAL,
32  )
33  self.clientclient = client
34 
35  async def _async_update_data(self) -> MetricData:
36  """Fetch state update."""
37  _LOGGER.debug("Updating Vallox state cache")
38 
39  try:
40  return await self.clientclient.fetch_metric_data()
41  except ValloxApiException as err:
42  raise UpdateFailed("Error during state cache update") from err
None __init__(self, HomeAssistant hass, str name, Vallox client)
Definition: coordinator.py:25