Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Data update coordinator for the Goal zero integration."""
2 
3 from datetime import timedelta
4 
5 from goalzero import Yeti, exceptions
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
10 
11 from .const import DOMAIN, LOGGER
12 
13 type GoalZeroConfigEntry = ConfigEntry[GoalZeroDataUpdateCoordinator]
14 
15 
17  """Data update coordinator for the Goal zero integration."""
18 
19  config_entry: GoalZeroConfigEntry
20 
21  def __init__(self, hass: HomeAssistant, api: Yeti) -> None:
22  """Initialize the coordinator."""
23  super().__init__(
24  hass=hass,
25  logger=LOGGER,
26  name=DOMAIN,
27  update_interval=timedelta(seconds=30),
28  )
29  self.apiapi = api
30 
31  async def _async_update_data(self) -> None:
32  """Fetch data from API endpoint."""
33  try:
34  await self.apiapi.get_state()
35  except exceptions.ConnectError as err:
36  raise UpdateFailed("Failed to communicate with device") from err
str|float get_state(dict[str, float] data, str key)
Definition: sensor.py:26