1 """Code to handle a Livisi switches."""
3 from __future__
import annotations
14 from .const
import DOMAIN, LIVISI_STATE_CHANGE, LOGGER, SWITCH_DEVICE_TYPES
15 from .coordinator
import LivisiDataUpdateCoordinator
16 from .entity
import LivisiEntity
21 config_entry: ConfigEntry,
22 async_add_entities: AddEntitiesCallback,
24 """Set up switch device."""
25 coordinator: LivisiDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
28 def handle_coordinator_update() -> None:
30 shc_devices: list[dict[str, Any]] = coordinator.data
31 entities: list[SwitchEntity] = []
32 for device
in shc_devices:
34 device[
"type"]
in SWITCH_DEVICE_TYPES
35 and device[
"id"]
not in coordinator.devices
38 config_entry, coordinator, device
40 LOGGER.debug(
"Include device type: %s", device[
"type"])
41 coordinator.devices.add(device[
"id"])
42 entities.append(livisi_switch)
45 config_entry.async_on_unload(
46 coordinator.async_add_listener(handle_coordinator_update)
51 """Represents the Livisi Switch."""
55 config_entry: ConfigEntry,
56 coordinator: LivisiDataUpdateCoordinator,
57 device: dict[str, Any],
59 """Initialize the Livisi switch."""
60 super().
__init__(config_entry, coordinator, device)
64 """Turn the entity on."""
65 response = await self.
aio_livisiaio_livisi.async_pss_set_state(
73 """Turn the entity off."""
74 response = await self.
aio_livisiaio_livisi.async_pss_set_state(
82 """Register callbacks."""
96 f
"{LIVISI_STATE_CHANGE}_{self._capability_id}",
103 """Update the state of the switch device."""
Any|None async_get_device_state(self, str capability, str key)
None update_states(self, bool state)
None __init__(self, ConfigEntry config_entry, LivisiDataUpdateCoordinator coordinator, dict[str, Any] device)
None async_turn_off(self, **Any kwargs)
None async_added_to_hass(self)
None async_turn_on(self, **Any kwargs)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)