Home Assistant Unofficial Reference 2024.12.1
coordinator.py
Go to the documentation of this file.
1 """DataUpdateCoordinator for the airtouch integration."""
2 
3 import logging
4 
5 from airtouch4pyapi.airtouch import AirTouchStatus
6 
7 from homeassistant.components.climate import SCAN_INTERVAL
8 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
9 
10 from .const import DOMAIN
11 
12 _LOGGER = logging.getLogger(__name__)
13 
14 
16  """Class to manage fetching Airtouch data."""
17 
18  def __init__(self, hass, airtouch):
19  """Initialize global Airtouch data updater."""
20  self.airtouchairtouch = airtouch
21 
22  super().__init__(
23  hass,
24  _LOGGER,
25  name=DOMAIN,
26  update_interval=SCAN_INTERVAL,
27  )
28 
29  async def _async_update_data(self):
30  """Fetch data from Airtouch."""
31  await self.airtouchairtouch.UpdateInfo()
32  if self.airtouchairtouch.Status != AirTouchStatus.OK:
33  raise UpdateFailed("Airtouch connection issue")
34  return {
35  "acs": [
36  {"ac_number": ac.AcNumber, "is_on": ac.IsOn}
37  for ac in self.airtouchairtouch.GetAcs()
38  ],
39  "groups": [
40  {
41  "group_number": group.GroupNumber,
42  "group_name": group.GroupName,
43  "is_on": group.IsOn,
44  }
45  for group in self.airtouchairtouch.GetGroups()
46  ],
47  }