1 """DataUpdateCoordinator for Smlight."""
3 from __future__
import annotations
5 from abc
import abstractmethod
6 from dataclasses
import dataclass
7 from typing
import TYPE_CHECKING
9 from pysmlight
import Api2, Info, Sensors
10 from pysmlight.const
import Settings, SettingsProp
11 from pysmlight.exceptions
import SmlightAuthError, SmlightConnectionError
12 from pysmlight.web
import Firmware
22 from .const
import DOMAIN, LOGGER, SCAN_FIRMWARE_INTERVAL, SCAN_INTERVAL
25 from .
import SmConfigEntry
30 """SMLIGHT data stored in the DataUpdateCoordinator."""
38 """SMLIGHT firmware data stored in the FirmwareUpdateCoordinator."""
41 esp_firmware: list[Firmware] |
None
42 zb_firmware: list[Firmware] |
None
46 """Base Coordinator for SMLIGHT."""
48 config_entry: SmConfigEntry
50 def __init__(self, hass: HomeAssistant, host: str, client: Api2) ->
None:
51 """Initialize the coordinator."""
55 name=f
"{DOMAIN}_{host}",
56 update_interval=SCAN_INTERVAL,
60 self.
unique_idunique_id: str |
None =
None
64 """Authenticate if needed during initial setup."""
65 if await self.
clientclient.check_auth_needed():
75 except SmlightAuthError
as err:
76 raise ConfigEntryAuthFailed
from err
79 raise ConfigEntryAuthFailed
84 if info.legacy_api == 2:
85 ir.async_create_issue(
88 "unsupported_firmware",
91 learn_more_url=
"https://smlight.tech/flasher/#SLZB-06",
92 severity=IssueSeverity.ERROR,
93 translation_key=
"unsupported_firmware",
99 except SmlightAuthError
as err:
100 raise ConfigEntryAuthFailed
from err
102 except SmlightConnectionError
as err:
107 """Update coordinator data."""
110 class SmDataUpdateCoordinator(SmBaseDataUpdateCoordinator[SmData]):
111 """Class to manage fetching SMLIGHT sensor data."""
114 """Update the sensor value from event."""
116 prop = SettingsProp[setting.name].value
117 setattr(self.
datadata.sensors, prop, value)
122 """Fetch sensor data from the SMLIGHT device."""
125 sensors = await self.
clientclient.get_sensors()
134 """Class to manage fetching SMLIGHT firmware update data from cloud."""
136 def __init__(self, hass: HomeAssistant, host: str, client: Api2) ->
None:
137 """Initialize the coordinator."""
138 super().
__init__(hass, host, client)
145 """Fetch data from the SMLIGHT device."""
150 esp_firmware=await self.
clientclient.get_firmware_version(info.fw_channel),
151 zb_firmware=await self.
clientclient.get_firmware_version(
152 info.fw_channel, device=info.model, mode=
"zigbee"
None __init__(self, HomeAssistant hass, str host, Api2 client)
_DataT _async_update_data(self)
_DataT _internal_update_data(self)
SmData _internal_update_data(self)
None update_setting(self, Settings setting, bool|int value)
None __init__(self, HomeAssistant hass, str host, Api2 client)
SmFwData _internal_update_data(self)
None update_interval(self, timedelta|None value)
timedelta|None update_interval(self)
None async_set_updated_data(self, _DataT data)
dict[str, Any]|None get_info(HomeAssistant hass)
def authenticate(HomeAssistant hass, host, port, servers)