Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """DataUpdateCoordinators for the sms integration."""
2 
3 import asyncio
4 from datetime import timedelta
5 import logging
6 
7 import gammu
8 
9 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
10 
11 from .const import DEFAULT_SCAN_INTERVAL
12 
13 _LOGGER = logging.getLogger(__name__)
14 
15 
17  """Signal strength coordinator."""
18 
19  def __init__(self, hass, gateway):
20  """Initialize signal strength coordinator."""
21  super().__init__(
22  hass,
23  _LOGGER,
24  name="Device signal state",
25  update_interval=timedelta(seconds=DEFAULT_SCAN_INTERVAL),
26  )
27  self._gateway_gateway = gateway
28 
29  async def _async_update_data(self):
30  """Fetch device signal quality."""
31  try:
32  async with asyncio.timeout(10):
33  return await self._gateway_gateway.get_signal_quality_async()
34  except gammu.GSMError as exc:
35  raise UpdateFailed(f"Error communicating with device: {exc}") from exc
36 
37 
39  """Network info coordinator."""
40 
41  def __init__(self, hass, gateway):
42  """Initialize network info coordinator."""
43  super().__init__(
44  hass,
45  _LOGGER,
46  name="Device network state",
47  update_interval=timedelta(seconds=DEFAULT_SCAN_INTERVAL),
48  )
49  self._gateway_gateway = gateway
50 
51  async def _async_update_data(self):
52  """Fetch device network info."""
53  try:
54  async with asyncio.timeout(10):
55  return await self._gateway_gateway.get_network_info_async()
56  except gammu.GSMError as exc:
57  raise UpdateFailed(f"Error communicating with device: {exc}") from exc