Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Data update coordinator for the Netgear LTE integration."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 from typing import TYPE_CHECKING
7 
8 from eternalegypt.eternalegypt import Error, Information, Modem
9 
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
12 
13 from .const import DOMAIN, LOGGER
14 
15 if TYPE_CHECKING:
16  from . import NetgearLTEConfigEntry
17 
18 
20  """Data update coordinator for the Netgear LTE integration."""
21 
22  config_entry: NetgearLTEConfigEntry
23 
24  def __init__(
25  self,
26  hass: HomeAssistant,
27  modem: Modem,
28  ) -> None:
29  """Initialize the coordinator."""
30  super().__init__(
31  hass=hass,
32  logger=LOGGER,
33  name=DOMAIN,
34  update_interval=timedelta(seconds=10),
35  )
36  self.modemmodem = modem
37 
38  async def _async_update_data(self) -> Information:
39  """Get the latest data."""
40  try:
41  return await self.modemmodem.information()
42  except Error as ex:
43  raise UpdateFailed(ex) from ex