1 """Support for SLZB-06 switches."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
10 from pysmlight
import Sensors, SettingsEvent
11 from pysmlight.const
import Settings
16 SwitchEntityDescription,
22 from .
import SmConfigEntry
23 from .coordinator
import SmDataUpdateCoordinator
24 from .entity
import SmEntity
26 _LOGGER = logging.getLogger(__name__)
29 @dataclass(frozen=True, kw_only=True)
31 """Class to describe a Switch entity."""
34 state_fn: Callable[[Sensors], bool |
None]
37 SWITCHES: list[SmSwitchEntityDescription] = [
40 translation_key=
"disable_led",
41 setting=Settings.DISABLE_LEDS,
42 state_fn=
lambda x: x.disable_leds,
46 translation_key=
"night_mode",
47 setting=Settings.NIGHT_MODE,
48 state_fn=
lambda x: x.night_mode,
51 key=
"auto_zigbee_update",
52 translation_key=
"auto_zigbee_update",
53 entity_category=EntityCategory.CONFIG,
54 setting=Settings.ZB_AUTOUPDATE,
55 entity_registry_enabled_default=
False,
56 state_fn=
lambda x: x.auto_zigbee,
60 translation_key=
"vpn_enabled",
61 setting=Settings.ENABLE_VPN,
62 entity_registry_enabled_default=
False,
63 state_fn=
lambda x: x.vpn_enabled,
71 async_add_entities: AddEntitiesCallback,
73 """Initialize switches for SLZB-06 device."""
74 coordinator = entry.runtime_data.data
80 """Representation of a SLZB-06 switch."""
82 coordinator: SmDataUpdateCoordinator
83 entity_description: SmSwitchEntityDescription
84 _attr_device_class = SwitchDeviceClass.SWITCH
88 coordinator: SmDataUpdateCoordinator,
89 description: SmSwitchEntityDescription,
91 """Initialize the switch."""
94 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.unique_id}-{description.key}"
96 self._page, self.
_toggle_toggle = description.setting.value
99 """Run when entity about to be added to hass."""
102 self.coordinator.client.sse.register_settings_cb(
108 """Set the state on SLZB device."""
109 await self.coordinator.client.set_toggle(self._page, self.
_toggle_toggle, state)
113 """Handle switch events from the SLZB device."""
114 if event.setting
is not None:
115 self.coordinator.update_setting(
120 """Turn the switch on."""
124 """Turn the switch off."""
129 """Return the state of the switch."""
130 return self.
entity_descriptionentity_description.state_fn(self.coordinator.data.sensors)
None set_smlight(self, bool state)
None __init__(self, SmDataUpdateCoordinator coordinator, SmSwitchEntityDescription description)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_added_to_hass(self)
None event_callback(self, SettingsEvent event)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, SmConfigEntry entry, AddEntitiesCallback async_add_entities)