Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """Coordinator for radiotherm."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 import logging
7 from urllib.error import URLError
8 
9 from radiotherm.validate import RadiothermTstatError
10 
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
13 
14 from .data import RadioThermInitData, RadioThermUpdate, async_get_data
15 
16 _LOGGER = logging.getLogger(__name__)
17 
18 UPDATE_INTERVAL = timedelta(seconds=15)
19 
20 
22  """DataUpdateCoordinator to gather data for radio thermostats."""
23 
24  def __init__(self, hass: HomeAssistant, init_data: RadioThermInitData) -> None:
25  """Initialize DataUpdateCoordinator."""
26  self.init_datainit_data = init_data
27  self._description_description = f"{init_data.name} ({init_data.host})"
28  super().__init__(
29  hass,
30  _LOGGER,
31  name=f"radiotherm {self.init_data.name}",
32  update_interval=UPDATE_INTERVAL,
33  )
34 
35  async def _async_update_data(self) -> RadioThermUpdate:
36  """Update data from the thermostat."""
37  try:
38  return await async_get_data(self.hasshass, self.init_datainit_data.tstat)
39  except RadiothermTstatError as ex:
40  msg = f"{self._description} was busy (invalid value returned): {ex}"
41  raise UpdateFailed(msg) from ex
42  except TimeoutError as ex:
43  msg = f"{self._description}) timed out waiting for a response: {ex}"
44  raise UpdateFailed(msg) from ex
45  except (OSError, URLError) as ex:
46  msg = f"{self._description} connection error: {ex}"
47  raise UpdateFailed(msg) from ex
None __init__(self, HomeAssistant hass, RadioThermInitData init_data)
Definition: coordinator.py:24
RadioThermUpdate async_get_data(HomeAssistant hass, CommonThermostat device)
Definition: data.py:73