1 """Representation of Z-Wave binary sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from zwave_js_server.client
import Client
as ZwaveClient
8 from zwave_js_server.const
import CommandClass
9 from zwave_js_server.const.command_class.lock
import DOOR_STATUS_PROPERTY
10 from zwave_js_server.const.command_class.notification
import (
11 CC_SPECIFIC_NOTIFICATION_TYPE,
13 from zwave_js_server.model.driver
import Driver
16 DOMAIN
as BINARY_SENSOR_DOMAIN,
17 BinarySensorDeviceClass,
19 BinarySensorEntityDescription,
27 from .const
import DATA_CLIENT, DOMAIN
28 from .discovery
import ZwaveDiscoveryInfo
29 from .entity
import ZWaveBaseEntity
34 NOTIFICATION_SMOKE_ALARM =
"1"
35 NOTIFICATION_CARBON_MONOOXIDE =
"2"
36 NOTIFICATION_CARBON_DIOXIDE =
"3"
37 NOTIFICATION_HEAT =
"4"
38 NOTIFICATION_WATER =
"5"
39 NOTIFICATION_ACCESS_CONTROL =
"6"
40 NOTIFICATION_HOME_SECURITY =
"7"
41 NOTIFICATION_POWER_MANAGEMENT =
"8"
42 NOTIFICATION_SYSTEM =
"9"
43 NOTIFICATION_EMERGENCY =
"10"
44 NOTIFICATION_CLOCK =
"11"
45 NOTIFICATION_APPLIANCE =
"12"
46 NOTIFICATION_HOME_HEALTH =
"13"
47 NOTIFICATION_SIREN =
"14"
48 NOTIFICATION_WATER_VALVE =
"15"
49 NOTIFICATION_WEATHER =
"16"
50 NOTIFICATION_IRRIGATION =
"17"
51 NOTIFICATION_GAS =
"18"
54 @dataclass(frozen=True)
56 """Represent a Z-Wave JS binary sensor entity description."""
59 states: tuple[str, ...] |
None =
None
62 @dataclass(frozen=True, kw_only=True)
64 """Represent the entity description for property name sensors."""
66 on_states: tuple[str, ...]
71 NOTIFICATION_SENSOR_MAPPINGS: tuple[NotificationZWaveJSEntityDescription, ...] = (
74 key=NOTIFICATION_SMOKE_ALARM,
76 device_class=BinarySensorDeviceClass.SMOKE,
80 key=NOTIFICATION_SMOKE_ALARM,
81 device_class=BinarySensorDeviceClass.PROBLEM,
85 key=NOTIFICATION_CARBON_MONOOXIDE,
87 device_class=BinarySensorDeviceClass.CO,
91 key=NOTIFICATION_CARBON_MONOOXIDE,
92 device_class=BinarySensorDeviceClass.PROBLEM,
96 key=NOTIFICATION_CARBON_DIOXIDE,
98 device_class=BinarySensorDeviceClass.GAS,
102 key=NOTIFICATION_CARBON_DIOXIDE,
103 device_class=BinarySensorDeviceClass.PROBLEM,
107 key=NOTIFICATION_HEAT,
108 states=(
"1",
"2",
"5",
"6"),
109 device_class=BinarySensorDeviceClass.HEAT,
113 key=NOTIFICATION_HEAT,
114 device_class=BinarySensorDeviceClass.PROBLEM,
118 key=NOTIFICATION_WATER,
119 states=(
"1",
"2",
"3",
"4"),
120 device_class=BinarySensorDeviceClass.MOISTURE,
124 key=NOTIFICATION_WATER,
125 device_class=BinarySensorDeviceClass.PROBLEM,
129 key=NOTIFICATION_ACCESS_CONTROL,
130 states=(
"1",
"2",
"3",
"4"),
131 device_class=BinarySensorDeviceClass.LOCK,
135 key=NOTIFICATION_ACCESS_CONTROL,
137 device_class=BinarySensorDeviceClass.PROBLEM,
138 entity_category=EntityCategory.DIAGNOSTIC,
142 key=NOTIFICATION_ACCESS_CONTROL,
145 device_class=BinarySensorDeviceClass.DOOR,
149 key=NOTIFICATION_HOME_SECURITY,
151 device_class=BinarySensorDeviceClass.SAFETY,
155 key=NOTIFICATION_HOME_SECURITY,
156 states=(
"3",
"4",
"9"),
157 device_class=BinarySensorDeviceClass.TAMPER,
158 entity_category=EntityCategory.DIAGNOSTIC,
162 key=NOTIFICATION_HOME_SECURITY,
164 device_class=BinarySensorDeviceClass.SAFETY,
168 key=NOTIFICATION_HOME_SECURITY,
170 device_class=BinarySensorDeviceClass.MOTION,
175 key=NOTIFICATION_POWER_MANAGEMENT,
178 device_class=BinarySensorDeviceClass.PLUG,
179 entity_category=EntityCategory.DIAGNOSTIC,
184 key=NOTIFICATION_POWER_MANAGEMENT,
185 states=(
"6",
"7",
"8",
"9"),
186 device_class=BinarySensorDeviceClass.SAFETY,
187 entity_category=EntityCategory.DIAGNOSTIC,
192 key=NOTIFICATION_POWER_MANAGEMENT,
193 states=(
"10",
"11",
"17"),
194 device_class=BinarySensorDeviceClass.BATTERY,
195 entity_category=EntityCategory.DIAGNOSTIC,
199 key=NOTIFICATION_SYSTEM,
200 states=(
"1",
"2",
"3",
"4",
"6",
"7"),
201 device_class=BinarySensorDeviceClass.PROBLEM,
202 entity_category=EntityCategory.DIAGNOSTIC,
206 key=NOTIFICATION_EMERGENCY,
207 states=(
"1",
"2",
"3"),
208 device_class=BinarySensorDeviceClass.PROBLEM,
212 key=NOTIFICATION_SIREN,
214 device_class=BinarySensorDeviceClass.SOUND,
218 key=NOTIFICATION_GAS,
219 states=(
"1",
"2",
"3",
"4"),
220 device_class=BinarySensorDeviceClass.GAS,
224 key=NOTIFICATION_GAS,
226 device_class=BinarySensorDeviceClass.PROBLEM,
232 PROPERTY_SENSOR_MAPPINGS: dict[str, PropertyZWaveJSEntityDescription] = {
234 key=DOOR_STATUS_PROPERTY,
236 device_class=BinarySensorDeviceClass.DOOR,
242 BOOLEAN_SENSOR_MAPPINGS: dict[int, BinarySensorEntityDescription] = {
244 key=
str(CommandClass.BATTERY),
245 device_class=BinarySensorDeviceClass.BATTERY,
246 entity_category=EntityCategory.DIAGNOSTIC,
253 info: ZwaveDiscoveryInfo,
254 ) -> bool | NotificationZWaveJSEntityDescription:
255 """Return if the notification CC Value is valid as binary sensor."""
256 if not info.primary_value.metadata.states:
258 return len(info.primary_value.metadata.states) > 1
263 config_entry: ConfigEntry,
264 async_add_entities: AddEntitiesCallback,
266 """Set up Z-Wave binary sensor from config entry."""
267 client: ZwaveClient = config_entry.runtime_data[DATA_CLIENT]
270 def async_add_binary_sensor(info: ZwaveDiscoveryInfo) ->
None:
271 """Add Z-Wave Binary Sensor."""
272 driver = client.driver
273 assert driver
is not None
274 entities: list[BinarySensorEntity] = []
276 if info.platform_hint ==
"notification":
281 for state_key
in info.primary_value.metadata.states:
286 notification_description: (
287 NotificationZWaveJSEntityDescription |
None
289 for description
in NOTIFICATION_SENSOR_MAPPINGS:
292 == info.primary_value.metadata.cc_specific[
293 CC_SPECIFIC_NOTIFICATION_TYPE
295 )
and (
not description.states
or state_key
in description.states):
296 notification_description = description
300 notification_description
301 and notification_description.off_state == state_key
306 config_entry, driver, info, state_key, notification_description
310 info.platform_hint ==
"property"
311 and info.primary_value.property_name
313 property_description := PROPERTY_SENSOR_MAPPINGS.get(
314 info.primary_value.property_name
320 config_entry, driver, info, property_description
323 elif info.platform_hint ==
"config_parameter":
333 config_entry.async_on_unload(
336 f
"{DOMAIN}_{config_entry.entry_id}_add_{BINARY_SENSOR_DOMAIN}",
337 async_add_binary_sensor,
343 """Representation of a Z-Wave binary_sensor."""
347 config_entry: ConfigEntry,
349 info: ZwaveDiscoveryInfo,
351 """Initialize a ZWaveBooleanBinarySensor entity."""
352 super().
__init__(config_entry, driver, info)
356 if description := BOOLEAN_SENSOR_MAPPINGS.get(
357 self.
infoinfo.primary_value.command_class
363 """Return if the sensor is on or off."""
364 if self.
infoinfo.primary_value.value
is None:
366 return bool(self.
infoinfo.primary_value.value)
370 """Representation of a Z-Wave binary_sensor from Notification CommandClass."""
374 config_entry: ConfigEntry,
376 info: ZwaveDiscoveryInfo,
378 description: NotificationZWaveJSEntityDescription |
None =
None,
380 """Initialize a ZWaveNotificationBinarySensor entity."""
381 super().
__init__(config_entry, driver, info)
388 alternate_value_name=self.
infoinfo.primary_value.metadata.states[self.
state_keystate_key]
394 """Return if the sensor is on or off."""
395 if self.
infoinfo.primary_value.value
is None:
401 """Representation of a Z-Wave binary_sensor from a property."""
403 entity_description: PropertyZWaveJSEntityDescription
407 config_entry: ConfigEntry,
409 info: ZwaveDiscoveryInfo,
410 description: PropertyZWaveJSEntityDescription,
412 """Initialize a ZWavePropertyBinarySensor entity."""
413 super().
__init__(config_entry, driver, info)
419 """Return if the sensor is on or off."""
420 if self.
infoinfo.primary_value.value
is None:
426 """Representation of a Z-Wave config parameter binary sensor."""
428 _attr_entity_category = EntityCategory.DIAGNOSTIC
431 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
433 """Initialize a ZWaveConfigParameterBinarySensor entity."""
434 super().
__init__(config_entry, driver, info)
436 property_key_name = self.
infoinfo.primary_value.property_key_name
439 alternate_value_name=self.
infoinfo.primary_value.property_name,
440 additional_info=[property_key_name]
if property_key_name
else None,
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info, str state_key, NotificationZWaveJSEntityDescription|None description=None)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info, PropertyZWaveJSEntityDescription description)
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_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
bool|NotificationZWaveJSEntityDescription is_valid_notification_binary_sensor(ZwaveDiscoveryInfo info)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)