Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """DataUpdateCoordinator for the Fast.com integration."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 
7 from fastdotcom import fast_com
8 
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
11 
12 from .const import DEFAULT_INTERVAL, DOMAIN, LOGGER
13 
14 
16  """Class to manage fetching Fast.com data API."""
17 
18  def __init__(self, hass: HomeAssistant) -> None:
19  """Initialize the coordinator for Fast.com."""
20  super().__init__(
21  hass,
22  LOGGER,
23  name=DOMAIN,
24  update_interval=timedelta(hours=DEFAULT_INTERVAL),
25  )
26 
27  async def _async_update_data(self) -> float:
28  """Run an executor job to retrieve Fast.com data."""
29  try:
30  return await self.hasshass.async_add_executor_job(fast_com)
31  except Exception as exc:
32  raise UpdateFailed(f"Error communicating with Fast.com: {exc}") from exc