Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """The totalconnect component."""
2 
3 from datetime import timedelta
4 import logging
5 
6 from total_connect_client.client import TotalConnectClient
7 from total_connect_client.exceptions import (
8  AuthenticationError,
9  ServiceUnavailable,
10  TotalConnectError,
11 )
12 
13 from homeassistant.config_entries import ConfigEntry
14 from homeassistant.core import HomeAssistant
15 from homeassistant.exceptions import ConfigEntryAuthFailed
16 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
17 
18 from .const import DOMAIN
19 
20 SCAN_INTERVAL = timedelta(seconds=30)
21 _LOGGER = logging.getLogger(__name__)
22 
23 
25  """Class to fetch data from TotalConnect."""
26 
27  config_entry: ConfigEntry
28 
29  def __init__(self, hass: HomeAssistant, client: TotalConnectClient) -> None:
30  """Initialize."""
31  self.clientclient = client
32  super().__init__(
33  hass, logger=_LOGGER, name=DOMAIN, update_interval=SCAN_INTERVAL
34  )
35 
36  async def _async_update_data(self) -> None:
37  """Update data."""
38  await self.hasshass.async_add_executor_job(self.sync_update_datasync_update_data)
39 
40  def sync_update_data(self) -> None:
41  """Fetch synchronous data from TotalConnect."""
42  try:
43  for location_id in self.clientclient.locations:
44  self.clientclient.locations[location_id].get_panel_meta_data()
45  except AuthenticationError as exception:
46  # should only encounter if password changes during operation
48  "TotalConnect authentication failed during operation."
49  ) from exception
50  except ServiceUnavailable as exception:
51  raise UpdateFailed(
52  "Error connecting to TotalConnect or the service is unavailable. "
53  "Check https://status.resideo.com/ for outages."
54  ) from exception
55  except TotalConnectError as exception:
56  raise UpdateFailed(exception) from exception
57  except ValueError as exception:
58  raise UpdateFailed("Unknown state from TotalConnect") from exception
None __init__(self, HomeAssistant hass, TotalConnectClient client)
Definition: coordinator.py:29