Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Coordinator for the Environment Canada (EC) component."""
2 
3 import logging
4 import xml.etree.ElementTree as ET
5 
6 from env_canada import ec_exc
7 
8 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
9 
10 from .const import DOMAIN
11 
12 _LOGGER = logging.getLogger(__name__)
13 
14 
16  """Class to manage fetching EC data."""
17 
18  def __init__(self, hass, ec_data, name, update_interval):
19  """Initialize global EC data updater."""
20  super().__init__(
21  hass, _LOGGER, name=f"{DOMAIN} {name}", update_interval=update_interval
22  )
23  self.ec_dataec_data = ec_data
24  self.last_update_successlast_update_successlast_update_success = False
25 
26  async def _async_update_data(self):
27  """Fetch data from EC."""
28  try:
29  await self.ec_dataec_data.update()
30  except (ET.ParseError, ec_exc.UnknownStationId) as ex:
31  raise UpdateFailed(f"Error fetching {self.name} data: {ex}") from ex
32  return self.ec_dataec_data
IssData update(pyiss.ISS iss)
Definition: __init__.py:33