1 """SwitchBee integration Coordinator."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from datetime
import timedelta
9 from switchbee.api
import CentralUnitPolling, CentralUnitWsRPC
10 from switchbee.api.central_unit
import SwitchBeeError
11 from switchbee.device
import DeviceType, SwitchBeeBaseDevice
17 from .const
import DOMAIN, SCAN_INTERVAL_SEC
19 _LOGGER = logging.getLogger(__name__)
23 """Class to manage fetching SwitchBee data API."""
28 swb_api: CentralUnitPolling | CentralUnitWsRPC,
31 self.api: CentralUnitPolling | CentralUnitWsRPC = swb_api
33 assert self.api.mac
is not None
36 if self.api.unique_id
is not None
43 update_interval=
timedelta(seconds=SCAN_INTERVAL_SEC[type(self.api)]),
47 if isinstance(self.api, CentralUnitWsRPC):
52 """Manually update data and notify listeners."""
53 assert isinstance(self.api, CentralUnitWsRPC)
54 _LOGGER.debug(
"Received update: %s", push_data)
58 """Update data via library."""
63 "Central Unit re-connected again due to invalid token, total %i",
68 if not self.api.devices:
71 await self.api.fetch_configuration(
74 DeviceType.TimedSwitch,
75 DeviceType.GroupSwitch,
76 DeviceType.TimedPowerSwitch,
81 DeviceType.Thermostat,
85 except SwitchBeeError
as exp:
87 f
"Error communicating with API: {exp}"
90 _LOGGER.debug(
"Loaded devices")
94 await self.api.fetch_states()
95 except SwitchBeeError
as exp:
97 f
"Error communicating with API: {exp}"
100 return self.api.devices
Mapping[int, SwitchBeeBaseDevice] _async_update_data(self)
None __init__(self, HomeAssistant hass, CentralUnitPolling|CentralUnitWsRPC swb_api)
None _async_handle_update(self, dict push_data)
None async_set_updated_data(self, _DataT data)