1 """Code to handle a Livisi switches."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from aiolivisi.const
import CAPABILITY_MAP
16 from .const
import DOMAIN, LIVISI_REACHABILITY_CHANGE
17 from .coordinator
import LivisiDataUpdateCoordinator
21 """Represents a base livisi entity."""
23 _attr_has_entity_name =
True
27 config_entry: ConfigEntry,
28 coordinator: LivisiDataUpdateCoordinator,
29 device: dict[str, Any],
31 use_room_as_device_name: bool =
False,
33 """Initialize the common properties of a Livisi device."""
35 self.capabilities: Mapping[str, Any] = device[CAPABILITY_MAP]
37 name = device[
"config"][
"name"]
38 unique_id = device[
"id"]
40 room_id: str |
None = device.get(
"location")
41 room_name: str |
None =
None
42 if room_id
is not None:
43 room_name = coordinator.rooms.get(room_id)
54 if use_room_as_device_name
and room_name
is not None:
56 device_name = room_name
59 identifiers={(DOMAIN, unique_id)},
60 manufacturer=device[
"manufacturer"],
63 suggested_area=room_name,
64 via_device=(DOMAIN, config_entry.entry_id),
69 """Register callback for reachability."""
74 f
"{LIVISI_REACHABILITY_CHANGE}_{self.unique_id}",
81 """Update the reachability of the device."""
83 self.async_write_ha_state()
None update_reachability(self, bool is_reachable)
None __init__(self, ConfigEntry config_entry, LivisiDataUpdateCoordinator coordinator, dict[str, Any] device, *bool use_room_as_device_name=False)
None async_added_to_hass(self)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)