1 """Representation of Z-Wave switches."""
3 from __future__
import annotations
7 from zwave_js_server.client
import Client
as ZwaveClient
8 from zwave_js_server.const
import TARGET_VALUE_PROPERTY
9 from zwave_js_server.const.command_class.barrier_operator
import (
10 BarrierEventSignalingSubsystemState,
12 from zwave_js_server.model.driver
import Driver
21 from .const
import DATA_CLIENT, DOMAIN
22 from .discovery
import ZwaveDiscoveryInfo
23 from .entity
import ZWaveBaseEntity
30 config_entry: ConfigEntry,
31 async_add_entities: AddEntitiesCallback,
33 """Set up Z-Wave sensor from config entry."""
34 client: ZwaveClient = config_entry.runtime_data[DATA_CLIENT]
37 def async_add_switch(info: ZwaveDiscoveryInfo) ->
None:
38 """Add Z-Wave Switch."""
39 driver = client.driver
40 assert driver
is not None
41 entities: list[ZWaveBaseEntity] = []
42 if info.platform_hint ==
"barrier_event_signaling_state":
46 elif info.platform_hint ==
"config_parameter":
48 elif info.platform_hint ==
"indicator":
51 entities.append(
ZWaveSwitch(config_entry, driver, info))
55 config_entry.async_on_unload(
58 f
"{DOMAIN}_{config_entry.entry_id}_add_{SWITCH_DOMAIN}",
65 """Representation of a Z-Wave switch."""
68 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
70 """Initialize the switch."""
71 super().
__init__(config_entry, driver, info)
77 """Return a boolean for the state of the switch."""
78 if self.
infoinfo.primary_value.value
is None:
81 return bool(self.
infoinfo.primary_value.value)
84 """Turn the switch on."""
89 """Turn the switch off."""
95 """Representation of a Z-Wave Indicator CC switch."""
98 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
100 """Initialize the switch."""
101 super().
__init__(config_entry, driver, info)
107 """Switch is used to turn on/off a barrier device's event signaling subsystem."""
111 config_entry: ConfigEntry,
113 info: ZwaveDiscoveryInfo,
115 """Initialize a ZWaveBarrierEventSignalingSwitch entity."""
116 super().
__init__(config_entry, driver, info)
117 self.
_state_state: bool |
None =
None
126 """Call when a watched value is added or updated."""
131 """Return a boolean for the state of the switch."""
135 """Turn the switch on."""
137 self.
infoinfo.primary_value, BarrierEventSignalingSubsystemState.ON
144 """Turn the switch off."""
146 self.
infoinfo.primary_value, BarrierEventSignalingSubsystemState.OFF
155 if self.
infoinfo.primary_value.value
is not None:
157 self.
infoinfo.primary_value.value == BarrierEventSignalingSubsystemState.ON
162 """Representation of a Z-Wave config parameter switch."""
164 _attr_entity_category = EntityCategory.CONFIG
167 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
169 """Initialize a ZWaveConfigParameterSwitch entity."""
170 super().
__init__(config_entry, driver, info)
172 property_key_name = self.
infoinfo.primary_value.property_key_name
175 alternate_value_name=self.
infoinfo.primary_value.property_name,
176 additional_info=[property_key_name]
if property_key_name
else None,
180 """Turn the switch on."""
184 """Turn the switch off."""
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 async_turn_on(self, **Any kwargs)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None on_value_update(self)
None async_turn_off(self, **Any kwargs)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None async_turn_on(self, **Any kwargs)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None async_turn_off(self, **Any kwargs)
None async_write_ha_state(self)
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)