1 """Representation of Z-Wave buttons."""
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.node
import Node
as ZwaveNode
16 from .const
import DATA_CLIENT, DOMAIN, LOGGER
17 from .discovery
import ZwaveDiscoveryInfo
18 from .entity
import ZWaveBaseEntity
19 from .helpers
import get_device_info, get_valueless_base_unique_id
26 config_entry: ConfigEntry,
27 async_add_entities: AddEntitiesCallback,
29 """Set up Z-Wave button from config entry."""
30 client: ZwaveClient = config_entry.runtime_data[DATA_CLIENT]
33 def async_add_button(info: ZwaveDiscoveryInfo) ->
None:
34 """Add Z-Wave Button."""
35 driver = client.driver
36 assert driver
is not None
37 entities: list[ZWaveBaseEntity] = []
38 if info.platform_hint ==
"notification idle":
46 def async_add_ping_button_entity(node: ZwaveNode) ->
None:
47 """Add ping button entity."""
48 driver = client.driver
49 assert driver
is not None
52 config_entry.async_on_unload(
55 f
"{DOMAIN}_{config_entry.entry_id}_add_ping_button_entity",
56 async_add_ping_button_entity,
60 config_entry.async_on_unload(
63 f
"{DOMAIN}_{config_entry.entry_id}_add_{BUTTON_DOMAIN}",
70 """Representation of a ZWave button entity for a boolean value."""
73 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
75 """Initialize entity."""
76 super().
__init__(config_entry, driver, info)
80 """Press the button."""
85 """Representation of a ping button entity."""
87 _attr_should_poll =
False
88 _attr_entity_category = EntityCategory.CONFIG
89 _attr_has_entity_name =
True
90 _attr_translation_key =
"ping"
92 def __init__(self, driver: Driver, node: ZwaveNode) ->
None:
93 """Initialize a ping Z-Wave device button entity."""
108 "There is no value to refresh for this entity so the zwave_js.refresh_value"
109 " service won't work for it"
113 """Call when entity is added."""
114 self.async_on_remove(
117 f
"{DOMAIN}_{self.unique_id}_poll_value",
125 self.async_on_remove(
128 f
"{DOMAIN}_{self._base_unique_id}_remove_entity",
134 """Press the button."""
135 self.hass.async_create_task(self.
nodenode.async_ping())
139 """Button to idle Notification CC values."""
141 _attr_entity_category = EntityCategory.CONFIG
144 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
146 """Initialize a ZWaveNotificationIdleButton entity."""
147 super().
__init__(config_entry, driver, info)
149 alternate_value_name=self.
infoinfo.primary_value.property_name,
150 additional_info=[self.
infoinfo.primary_value.property_key_name],
156 """Press the button."""
157 await self.
infoinfo.node.async_manually_idle_notification_value(
158 self.
infoinfo.primary_value
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)
SetValueResult|None _async_set_value(self, ZwaveValue value, Any new_value, dict|None options=None, bool|None wait_for_result=None)
DeviceInfo get_device_info(str coordinates, str name)
str get_valueless_base_unique_id(Driver driver, ZwaveNode node)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)