1 """Support for Z-Wave controls using the select platform."""
3 from __future__
import annotations
5 from typing
import cast
7 from zwave_js_server.client
import Client
as ZwaveClient
8 from zwave_js_server.const
import TARGET_VALUE_PROPERTY, CommandClass
9 from zwave_js_server.const.command_class.lock
import TARGET_MODE_PROPERTY
10 from zwave_js_server.const.command_class.sound_switch
import TONE_ID_PROPERTY, ToneID
11 from zwave_js_server.model.driver
import Driver
20 from .const
import DATA_CLIENT, DOMAIN
21 from .discovery
import ZwaveDiscoveryInfo
22 from .entity
import ZWaveBaseEntity
29 config_entry: ConfigEntry,
30 async_add_entities: AddEntitiesCallback,
32 """Set up Z-Wave Select entity from Config Entry."""
33 client: ZwaveClient = config_entry.runtime_data[DATA_CLIENT]
36 def async_add_select(info: ZwaveDiscoveryInfo) ->
None:
37 """Add Z-Wave select entity."""
38 driver = client.driver
39 assert driver
is not None
40 entities: list[ZWaveBaseEntity] = []
41 if info.platform_hint ==
"Default tone":
43 elif info.platform_hint ==
"multilevel_switch":
47 elif info.platform_hint ==
"config_parameter":
51 elif info.platform_hint ==
"door_lock":
57 config_entry.async_on_unload(
60 f
"{DOMAIN}_{config_entry.entry_id}_add_{SELECT_DOMAIN}",
67 """Representation of a Z-Wave select entity."""
69 _attr_entity_category = EntityCategory.CONFIG
72 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
74 """Initialize a ZwaveSelectEntity entity."""
75 super().
__init__(config_entry, driver, info)
83 """Return the selected entity option to represent the entity state."""
84 if self.
infoinfo.primary_value.value
is None:
87 self.
infoinfo.primary_value.metadata.states.get(
88 str(self.
infoinfo.primary_value.value), self.
infoinfo.primary_value.value
93 """Change the selected option."""
96 for key, val
in self.
infoinfo.primary_value.metadata.states.items()
103 """Representation of a Z-Wave door lock CC mode select entity."""
106 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
108 """Initialize a ZWaveDoorLockSelectEntity entity."""
109 super().
__init__(config_entry, driver, info)
113 """Change the selected option."""
117 for key, val
in self.
infoinfo.primary_value.metadata.states.items()
124 """Representation of a Z-Wave config parameter select."""
126 _attr_entity_category = EntityCategory.CONFIG
129 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
131 """Initialize a ZWaveConfigParameterSelect entity."""
132 super().
__init__(config_entry, driver, info)
134 property_key_name = self.
infoinfo.primary_value.property_key_name
137 alternate_value_name=self.
infoinfo.primary_value.property_name,
138 additional_info=[property_key_name]
if property_key_name
else None,
143 """Representation of a Z-Wave default tone select entity."""
145 _attr_entity_category = EntityCategory.CONFIG
148 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
150 """Initialize a ZwaveDefaultToneSelectEntity entity."""
151 super().
__init__(config_entry, driver, info)
153 TONE_ID_PROPERTY, command_class=CommandClass.SOUND_SWITCH
161 """Return a set of selectable options."""
166 for key, val
in self.
_tones_value_tones_value.metadata.states.items()
167 if int(key)
not in (ToneID.DEFAULT, ToneID.OFF)
172 """Return the selected entity option to represent the entity state."""
177 str(self.
infoinfo.primary_value.value), self.
infoinfo.primary_value.value
182 """Change the selected option."""
187 for key, val
in self.
_tones_value_tones_value.metadata.states.items()
194 """Representation of a Z-Wave Multilevel Switch CC select entity."""
197 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
199 """Initialize a ZwaveSelectEntity entity."""
200 super().
__init__(config_entry, driver, info)
202 assert self.
infoinfo.platform_data_template
204 dict[int, str], self.
infoinfo.platform_data_template.static_data
212 """Return the selected entity option to represent the entity state."""
213 if self.
infoinfo.primary_value.value
is None:
217 int(self.
infoinfo.primary_value.value), self.
infoinfo.primary_value.value
222 """Change the selected option."""
224 key = next(key
for key, val
in self.
_lookup_map_lookup_map.items()
if val == option)
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)
ZwaveValue|None get_zwave_value(self, str|int value_property, int|None command_class=None, int|None endpoint=None, int|str|None value_property_key=None, bool add_to_watched_value_ids=True, bool check_all_endpoints=False)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None async_select_option(self, str option)
None async_select_option(self, str option)
str|None current_option(self)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None async_select_option(self, str option)
str|None current_option(self)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
str|None current_option(self)
None async_select_option(self, str option)
web.Response get(self, web.Request request, str config_key)
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)