Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Data Update Coordinator for IMGW-PIB integration."""
2 
3 import logging
4 
5 from imgw_pib import ApiError, HydrologicalData, ImgwPib
6 
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
9 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
10 
11 from .const import DOMAIN, UPDATE_INTERVAL
12 
13 _LOGGER = logging.getLogger(__name__)
14 
15 
17  """Class to manage fetching IMGW-PIB data API."""
18 
19  def __init__(
20  self,
21  hass: HomeAssistant,
22  imgwpib: ImgwPib,
23  station_id: str,
24  ) -> None:
25  """Initialize."""
26  self.imgwpibimgwpib = imgwpib
27  self.station_idstation_id = station_id
28  self.device_infodevice_info = DeviceInfo(
29  entry_type=DeviceEntryType.SERVICE,
30  identifiers={(DOMAIN, station_id)},
31  manufacturer="IMGW-PIB",
32  name=f"{imgwpib.hydrological_stations[station_id]}",
33  configuration_url=f"https://hydro.imgw.pl/#/station/hydro/{station_id}",
34  )
35 
36  super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=UPDATE_INTERVAL)
37 
38  async def _async_update_data(self) -> HydrologicalData:
39  """Update data via internal method."""
40  try:
41  return await self.imgwpibimgwpib.get_hydrological_data()
42  except ApiError as err:
43  raise UpdateFailed(err) from err
None __init__(self, HomeAssistant hass, ImgwPib imgwpib, str station_id)
Definition: coordinator.py:24