Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """SFR Box coordinator."""
2 
3 from collections.abc import Callable, Coroutine
4 from datetime import timedelta
5 import logging
6 from typing import Any
7 
8 from sfrbox_api.bridge import SFRBox
9 from sfrbox_api.exceptions import SFRBoxError
10 
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
13 
14 _LOGGER = logging.getLogger(__name__)
15 _SCAN_INTERVAL = timedelta(minutes=1)
16 
17 
18 class SFRDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT | None]):
19  """Coordinator to manage data updates."""
20 
21  def __init__(
22  self,
23  hass: HomeAssistant,
24  box: SFRBox,
25  name: str,
26  method: Callable[[SFRBox], Coroutine[Any, Any, _DataT | None]],
27  ) -> None:
28  """Initialize coordinator."""
29  self.boxbox = box
30  self._method_method = method
31  super().__init__(hass, _LOGGER, name=name, update_interval=_SCAN_INTERVAL)
32 
33  async def _async_update_data(self) -> _DataT | None:
34  """Update data."""
35  try:
36  return await self._method_method(self.boxbox)
37  except SFRBoxError as err:
38  raise UpdateFailed from err
None __init__(self, HomeAssistant hass, SFRBox box, str name, Callable[[SFRBox], Coroutine[Any, Any, _DataT|None]] method)
Definition: coordinator.py:27