Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """The GIOS component."""
2 
3 from __future__ import annotations
4 
5 import asyncio
6 import logging
7 
8 from aiohttp import ClientSession
9 from aiohttp.client_exceptions import ClientConnectorError
10 from gios import Gios
11 from gios.exceptions import GiosError
12 from gios.model import GiosSensors
13 
14 from homeassistant.core import HomeAssistant
15 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
16 
17 from .const import API_TIMEOUT, DOMAIN, SCAN_INTERVAL
18 
19 _LOGGER = logging.getLogger(__name__)
20 
21 
23  """Define an object to hold GIOS data."""
24 
25  def __init__(
26  self, hass: HomeAssistant, session: ClientSession, station_id: int
27  ) -> None:
28  """Class to manage fetching GIOS data API."""
29  self.giosgios = Gios(station_id, session)
30 
31  super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL)
32 
33  async def _async_update_data(self) -> GiosSensors:
34  """Update data via library."""
35  try:
36  async with asyncio.timeout(API_TIMEOUT):
37  return await self.giosgios.async_update()
38  except (GiosError, ClientConnectorError) as error:
39  raise UpdateFailed(error) from error
None __init__(self, HomeAssistant hass, ClientSession session, int station_id)
Definition: coordinator.py:27