1 """Support for the Dynalite devices as entities."""
3 from __future__
import annotations
5 from abc
import ABC, abstractmethod
6 from collections.abc
import Callable
16 from .bridge
import DynaliteBridge
17 from .const
import DOMAIN, LOGGER
22 config_entry: ConfigEntry,
23 async_add_entities: AddEntitiesCallback,
25 entity_from_device: Callable,
27 """Record the async_add_entities function to add them later when received from Dynalite."""
28 LOGGER.debug(
"Setting up %s entry = %s", platform, config_entry.data)
29 bridge = hass.data[DOMAIN][config_entry.entry_id]
32 def async_add_entities_platform(devices):
34 added_entities = [entity_from_device(device, bridge)
for device
in devices]
37 bridge.register_add_devices(platform, async_add_entities_platform)
41 """Base class for the Dynalite entities."""
43 _attr_has_entity_name =
True
46 def __init__(self, device: Any, bridge: DynaliteBridge) ->
None:
47 """Initialize the base class."""
54 """Return the unique ID of the entity."""
55 return self.
_device_device.unique_id
59 """Return if entity is available."""
60 return self.
_device_device.available
64 """Device info for this entity."""
66 identifiers={(DOMAIN, self.
_device_device.unique_id)},
67 manufacturer=
"Dynalite",
72 """Handle addition to hass: restore state and register to dispatch."""
80 LOGGER.warning(
"Restore state not available for %s", self.
entity_identity_id)
93 self.
_bridge_bridge.update_signal(),
100 """Initialize the state from cache."""
103 """Unregister signal dispatch listeners when being removed."""
104 for unsub
in self._unsub_dispatchers:
None async_will_remove_from_hass(self)
def initialize_state(self, state)
DeviceInfo device_info(self)
None __init__(self, Any device, DynaliteBridge bridge)
None async_added_to_hass(self)
None async_schedule_update_ha_state(self, bool force_refresh=False)
State|None async_get_last_state(self)
None async_setup_entry_base(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities, str platform, Callable entity_from_device)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)