Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """The ecoforest coordinator."""
2 
3 import logging
4 
5 from pyecoforest.api import EcoforestApi
6 from pyecoforest.exceptions import EcoforestError
7 from pyecoforest.models.device import Device
8 
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
11 
12 from .const import POLLING_INTERVAL
13 
14 _LOGGER = logging.getLogger(__name__)
15 
16 
18  """DataUpdateCoordinator to gather data from ecoforest device."""
19 
20  def __init__(self, hass: HomeAssistant, api: EcoforestApi) -> None:
21  """Initialize DataUpdateCoordinator."""
22 
23  super().__init__(
24  hass,
25  _LOGGER,
26  name="ecoforest",
27  update_interval=POLLING_INTERVAL,
28  )
29  self.apiapi = api
30 
31  async def _async_update_data(self) -> Device:
32  """Fetch all device and sensor data from api."""
33  try:
34  data = await self.apiapi.get()
35  except EcoforestError as err:
36  raise UpdateFailed(f"Error communicating with API: {err}") from err
37 
38  _LOGGER.debug("Ecoforest data: %s", data)
39  return data
None __init__(self, HomeAssistant hass, EcoforestApi api)
Definition: coordinator.py:20
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88