1 """Support for Z-Wave controls using the event platform."""
3 from __future__
import annotations
5 from zwave_js_server.client
import Client
as ZwaveClient
6 from zwave_js_server.model.driver
import Driver
7 from zwave_js_server.model.value
import Value, ValueNotification
15 from .const
import ATTR_VALUE, DATA_CLIENT, DOMAIN
16 from .discovery
import ZwaveDiscoveryInfo
17 from .entity
import ZWaveBaseEntity
24 config_entry: ConfigEntry,
25 async_add_entities: AddEntitiesCallback,
27 """Set up Z-Wave Event entity from Config Entry."""
28 client: ZwaveClient = config_entry.runtime_data[DATA_CLIENT]
31 def async_add_event(info: ZwaveDiscoveryInfo) ->
None:
32 """Add Z-Wave event entity."""
33 driver = client.driver
34 assert driver
is not None
35 entities: list[ZWaveBaseEntity] = [
ZwaveEventEntity(config_entry, driver, info)]
38 config_entry.async_on_unload(
41 f
"{DOMAIN}_{config_entry.entry_id}_add_{EVENT_DOMAIN}",
48 """Return a string with the command class and label."""
49 label = value.metadata.label
52 return f
"{value.command_class_name.capitalize()} {label}".strip()
56 """Representation of a Z-Wave event entity."""
59 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
61 """Initialize a ZwaveEventEntity entity."""
62 super().
__init__(config_entry, driver, info)
63 value = self.
valuevalue = info.primary_value
64 self.
statesstates: dict[int, str] = {}
66 if states := value.metadata.states:
68 self.
statesstates = {
int(k): v
for k, v
in states.items()}
76 """Handle a value notification event."""
78 value = self.
valuevalue
80 value_notification.command_class != value.command_class
81 or value_notification.endpoint != value.endpoint
82 or value_notification.property_ != value.property_
83 or value_notification.property_key != value.property_key
84 or (notification_value := value_notification.value)
is None
88 self._trigger_event(event_name, {ATTR_VALUE: notification_value})
92 """Call when entity is added."""
95 self.
infoinfo.node.on(
str generate_name(self, bool include_value_name=False, str|None alternate_value_name=None, Sequence[str|None]|None additional_info=None, str|None name_prefix=None)
None async_added_to_hass(self)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None _async_handle_event(self, ValueNotification value_notification)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
web.Response get(self, web.Request request, str config_key)
str _cc_and_label(Value value)
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)