1 """Representation of Z-Wave sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable, Mapping
6 from dataclasses
import dataclass
9 import voluptuous
as vol
10 from zwave_js_server.client
import Client
as ZwaveClient
11 from zwave_js_server.const
import CommandClass
12 from zwave_js_server.const.command_class.meter
import (
13 RESET_METER_OPTION_TARGET_VALUE,
14 RESET_METER_OPTION_TYPE,
16 from zwave_js_server.exceptions
import BaseZwaveJSServerError
17 from zwave_js_server.model.controller
import Controller
18 from zwave_js_server.model.controller.statistics
import ControllerStatistics
19 from zwave_js_server.model.driver
import Driver
20 from zwave_js_server.model.node
import Node
as ZwaveNode
21 from zwave_js_server.model.node.statistics
import NodeStatistics
22 from zwave_js_server.util.command_class.meter
import get_meter_type
25 DOMAIN
as SENSOR_DOMAIN,
28 SensorEntityDescription,
33 CONCENTRATION_PARTS_PER_MILLION,
36 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
39 UnitOfElectricCurrent,
40 UnitOfElectricPotential,
54 from .binary_sensor
import is_valid_notification_binary_sensor
61 ENTITY_DESC_KEY_BATTERY,
64 ENTITY_DESC_KEY_CURRENT,
65 ENTITY_DESC_KEY_ENERGY_MEASUREMENT,
66 ENTITY_DESC_KEY_ENERGY_PRODUCTION_POWER,
67 ENTITY_DESC_KEY_ENERGY_PRODUCTION_TIME,
68 ENTITY_DESC_KEY_ENERGY_PRODUCTION_TODAY,
69 ENTITY_DESC_KEY_ENERGY_PRODUCTION_TOTAL,
70 ENTITY_DESC_KEY_ENERGY_TOTAL_INCREASING,
71 ENTITY_DESC_KEY_HUMIDITY,
72 ENTITY_DESC_KEY_ILLUMINANCE,
73 ENTITY_DESC_KEY_MEASUREMENT,
74 ENTITY_DESC_KEY_POWER,
75 ENTITY_DESC_KEY_POWER_FACTOR,
76 ENTITY_DESC_KEY_PRESSURE,
77 ENTITY_DESC_KEY_SIGNAL_STRENGTH,
78 ENTITY_DESC_KEY_TARGET_TEMPERATURE,
79 ENTITY_DESC_KEY_TEMPERATURE,
80 ENTITY_DESC_KEY_TOTAL_INCREASING,
81 ENTITY_DESC_KEY_UV_INDEX,
82 ENTITY_DESC_KEY_VOLTAGE,
86 from .discovery
import ZwaveDiscoveryInfo
87 from .discovery_data_template
import (
88 NumericSensorDataTemplate,
89 NumericSensorDataTemplateData,
91 from .entity
import ZWaveBaseEntity
92 from .helpers
import get_device_info, get_valueless_base_unique_id
93 from .migrate
import async_migrate_statistics_sensors
99 ENTITY_DESCRIPTION_KEY_DEVICE_CLASS_MAP: dict[
100 tuple[str, str], SensorEntityDescription
103 key=ENTITY_DESC_KEY_BATTERY,
104 device_class=SensorDeviceClass.BATTERY,
105 entity_category=EntityCategory.DIAGNOSTIC,
106 state_class=SensorStateClass.MEASUREMENT,
107 native_unit_of_measurement=PERCENTAGE,
110 key=ENTITY_DESC_KEY_CURRENT,
111 device_class=SensorDeviceClass.CURRENT,
112 state_class=SensorStateClass.MEASUREMENT,
113 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
116 key=ENTITY_DESC_KEY_VOLTAGE,
117 device_class=SensorDeviceClass.VOLTAGE,
118 state_class=SensorStateClass.MEASUREMENT,
119 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
120 suggested_display_precision=0,
123 ENTITY_DESC_KEY_VOLTAGE,
124 UnitOfElectricPotential.MILLIVOLT,
126 key=ENTITY_DESC_KEY_VOLTAGE,
127 device_class=SensorDeviceClass.VOLTAGE,
128 state_class=SensorStateClass.MEASUREMENT,
129 native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
132 ENTITY_DESC_KEY_ENERGY_TOTAL_INCREASING,
133 UnitOfEnergy.KILO_WATT_HOUR,
135 key=ENTITY_DESC_KEY_ENERGY_TOTAL_INCREASING,
136 device_class=SensorDeviceClass.ENERGY,
137 state_class=SensorStateClass.TOTAL_INCREASING,
138 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
141 key=ENTITY_DESC_KEY_POWER,
142 device_class=SensorDeviceClass.POWER,
143 state_class=SensorStateClass.MEASUREMENT,
144 native_unit_of_measurement=UnitOfPower.WATT,
147 key=ENTITY_DESC_KEY_POWER_FACTOR,
148 device_class=SensorDeviceClass.POWER_FACTOR,
149 state_class=SensorStateClass.MEASUREMENT,
150 native_unit_of_measurement=PERCENTAGE,
153 key=ENTITY_DESC_KEY_CO,
154 device_class=SensorDeviceClass.CO,
155 state_class=SensorStateClass.MEASUREMENT,
156 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
159 key=ENTITY_DESC_KEY_CO2,
160 device_class=SensorDeviceClass.CO2,
161 state_class=SensorStateClass.MEASUREMENT,
162 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
165 key=ENTITY_DESC_KEY_HUMIDITY,
166 device_class=SensorDeviceClass.HUMIDITY,
167 state_class=SensorStateClass.MEASUREMENT,
168 native_unit_of_measurement=PERCENTAGE,
171 key=ENTITY_DESC_KEY_ILLUMINANCE,
172 device_class=SensorDeviceClass.ILLUMINANCE,
173 state_class=SensorStateClass.MEASUREMENT,
174 native_unit_of_measurement=LIGHT_LUX,
177 key=ENTITY_DESC_KEY_PRESSURE,
178 device_class=SensorDeviceClass.PRESSURE,
179 state_class=SensorStateClass.MEASUREMENT,
180 native_unit_of_measurement=UnitOfPressure.KPA,
183 key=ENTITY_DESC_KEY_PRESSURE,
184 device_class=SensorDeviceClass.PRESSURE,
185 state_class=SensorStateClass.MEASUREMENT,
186 native_unit_of_measurement=UnitOfPressure.PSI,
189 key=ENTITY_DESC_KEY_PRESSURE,
190 device_class=SensorDeviceClass.PRESSURE,
191 state_class=SensorStateClass.MEASUREMENT,
192 native_unit_of_measurement=UnitOfPressure.INHG,
195 key=ENTITY_DESC_KEY_PRESSURE,
196 device_class=SensorDeviceClass.PRESSURE,
197 state_class=SensorStateClass.MEASUREMENT,
198 native_unit_of_measurement=UnitOfPressure.MMHG,
201 ENTITY_DESC_KEY_SIGNAL_STRENGTH,
202 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
204 key=ENTITY_DESC_KEY_SIGNAL_STRENGTH,
205 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
206 entity_category=EntityCategory.DIAGNOSTIC,
207 entity_registry_enabled_default=
False,
208 state_class=SensorStateClass.MEASUREMENT,
209 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
212 key=ENTITY_DESC_KEY_TEMPERATURE,
213 device_class=SensorDeviceClass.TEMPERATURE,
214 state_class=SensorStateClass.MEASUREMENT,
215 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
218 ENTITY_DESC_KEY_TEMPERATURE,
219 UnitOfTemperature.FAHRENHEIT,
221 key=ENTITY_DESC_KEY_TEMPERATURE,
222 device_class=SensorDeviceClass.TEMPERATURE,
223 state_class=SensorStateClass.MEASUREMENT,
224 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
227 ENTITY_DESC_KEY_TARGET_TEMPERATURE,
228 UnitOfTemperature.CELSIUS,
230 key=ENTITY_DESC_KEY_TARGET_TEMPERATURE,
231 device_class=SensorDeviceClass.TEMPERATURE,
232 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
235 ENTITY_DESC_KEY_TARGET_TEMPERATURE,
236 UnitOfTemperature.FAHRENHEIT,
238 key=ENTITY_DESC_KEY_TARGET_TEMPERATURE,
239 device_class=SensorDeviceClass.TEMPERATURE,
240 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
243 ENTITY_DESC_KEY_ENERGY_PRODUCTION_TIME,
246 key=ENTITY_DESC_KEY_ENERGY_PRODUCTION_TIME,
247 name=
"Energy production time",
248 device_class=SensorDeviceClass.DURATION,
249 native_unit_of_measurement=UnitOfTime.SECONDS,
252 key=ENTITY_DESC_KEY_ENERGY_PRODUCTION_TIME,
253 device_class=SensorDeviceClass.DURATION,
254 native_unit_of_measurement=UnitOfTime.HOURS,
257 ENTITY_DESC_KEY_ENERGY_PRODUCTION_TODAY,
258 UnitOfEnergy.WATT_HOUR,
260 key=ENTITY_DESC_KEY_ENERGY_PRODUCTION_TODAY,
261 name=
"Energy production today",
262 device_class=SensorDeviceClass.ENERGY,
263 state_class=SensorStateClass.TOTAL_INCREASING,
264 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
267 ENTITY_DESC_KEY_ENERGY_PRODUCTION_TOTAL,
268 UnitOfEnergy.WATT_HOUR,
270 key=ENTITY_DESC_KEY_ENERGY_PRODUCTION_TOTAL,
271 name=
"Energy production total",
272 device_class=SensorDeviceClass.ENERGY,
273 state_class=SensorStateClass.TOTAL_INCREASING,
274 native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
277 ENTITY_DESC_KEY_ENERGY_PRODUCTION_POWER,
280 key=ENTITY_DESC_KEY_POWER,
281 name=
"Energy production power",
282 device_class=SensorDeviceClass.POWER,
283 state_class=SensorStateClass.MEASUREMENT,
284 native_unit_of_measurement=UnitOfPower.WATT,
289 ENTITY_DESCRIPTION_KEY_MAP = {
291 key=ENTITY_DESC_KEY_CO,
292 state_class=SensorStateClass.MEASUREMENT,
295 key=ENTITY_DESC_KEY_ENERGY_MEASUREMENT,
296 state_class=SensorStateClass.MEASUREMENT,
299 key=ENTITY_DESC_KEY_HUMIDITY,
300 state_class=SensorStateClass.MEASUREMENT,
303 key=ENTITY_DESC_KEY_ILLUMINANCE,
304 state_class=SensorStateClass.MEASUREMENT,
307 key=ENTITY_DESC_KEY_POWER_FACTOR,
308 state_class=SensorStateClass.MEASUREMENT,
311 key=ENTITY_DESC_KEY_SIGNAL_STRENGTH,
312 entity_category=EntityCategory.DIAGNOSTIC,
313 entity_registry_enabled_default=
False,
314 state_class=SensorStateClass.MEASUREMENT,
317 key=ENTITY_DESC_KEY_MEASUREMENT,
318 state_class=SensorStateClass.MEASUREMENT,
321 key=ENTITY_DESC_KEY_TOTAL_INCREASING,
322 state_class=SensorStateClass.TOTAL_INCREASING,
325 key=ENTITY_DESC_KEY_UV_INDEX,
326 state_class=SensorStateClass.MEASUREMENT,
327 native_unit_of_measurement=UV_INDEX,
333 statistics: ControllerStatistics | NodeStatistics, key: str
335 """Convert a string that represents a nested attr to a value."""
337 for _key
in key.split(
"."):
340 data = getattr(data, _key)
344 @dataclass(frozen=True, kw_only=True)
346 """Class to represent a Z-Wave JS statistics sensor entity description."""
348 convert: Callable[[ControllerStatistics | NodeStatistics, str], Any] = getattr
349 entity_registry_enabled_default: bool =
False
353 ENTITY_DESCRIPTION_CONTROLLER_STATISTICS_LIST = [
356 translation_key=
"successful_messages",
357 translation_placeholders={
"direction":
"TX"},
358 state_class=SensorStateClass.TOTAL,
362 translation_key=
"successful_messages",
363 translation_placeholders={
"direction":
"RX"},
364 state_class=SensorStateClass.TOTAL,
367 key=
"messages_dropped_tx",
368 translation_key=
"messages_dropped",
369 translation_placeholders={
"direction":
"TX"},
370 state_class=SensorStateClass.TOTAL,
373 key=
"messages_dropped_rx",
374 translation_key=
"messages_dropped",
375 translation_placeholders={
"direction":
"RX"},
376 state_class=SensorStateClass.TOTAL,
379 key=
"nak", translation_key=
"nak", state_class=SensorStateClass.TOTAL
382 key=
"can", translation_key=
"can", state_class=SensorStateClass.TOTAL
386 translation_key=
"timeout_ack",
387 state_class=SensorStateClass.TOTAL,
390 key=
"timeout_response",
391 translation_key=
"timeout_response",
392 state_class=SensorStateClass.TOTAL,
395 key=
"timeout_callback",
396 translation_key=
"timeout_callback",
397 state_class=SensorStateClass.TOTAL,
400 key=
"background_rssi.channel_0.average",
401 translation_key=
"average_background_rssi",
402 translation_placeholders={
"channel":
"0"},
403 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
404 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
405 convert=convert_nested_attr,
408 key=
"background_rssi.channel_0.current",
409 translation_key=
"current_background_rssi",
410 translation_placeholders={
"channel":
"0"},
411 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
412 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
413 state_class=SensorStateClass.MEASUREMENT,
414 convert=convert_nested_attr,
417 key=
"background_rssi.channel_1.average",
418 translation_key=
"average_background_rssi",
419 translation_placeholders={
"channel":
"1"},
420 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
421 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
422 convert=convert_nested_attr,
425 key=
"background_rssi.channel_1.current",
426 translation_key=
"current_background_rssi",
427 translation_placeholders={
"channel":
"1"},
428 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
429 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
430 state_class=SensorStateClass.MEASUREMENT,
431 convert=convert_nested_attr,
434 key=
"background_rssi.channel_2.average",
435 translation_key=
"average_background_rssi",
436 translation_placeholders={
"channel":
"2"},
437 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
438 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
439 convert=convert_nested_attr,
442 key=
"background_rssi.channel_2.current",
443 translation_key=
"current_background_rssi",
444 translation_placeholders={
"channel":
"2"},
445 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
446 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
447 state_class=SensorStateClass.MEASUREMENT,
448 convert=convert_nested_attr,
452 CONTROLLER_STATISTICS_KEY_MAP: dict[str, str] = {
453 "messages_tx":
"messagesTX",
454 "messages_rx":
"messagesRX",
455 "messages_dropped_tx":
"messagesDroppedTX",
456 "messages_dropped_rx":
"messagesDroppedRX",
459 "timeout_ack":
"timeoutAck",
460 "timeout_response":
"timeoutResponse",
461 "timeout_callback":
"timeoutCallback",
462 "background_rssi.channel_0.average":
"backgroundRSSI.channel0.average",
463 "background_rssi.channel_0.current":
"backgroundRSSI.channel0.current",
464 "background_rssi.channel_1.average":
"backgroundRSSI.channel1.average",
465 "background_rssi.channel_1.current":
"backgroundRSSI.channel1.current",
466 "background_rssi.channel_2.average":
"backgroundRSSI.channel2.average",
467 "background_rssi.channel_2.current":
"backgroundRSSI.channel2.current",
471 ENTITY_DESCRIPTION_NODE_STATISTICS_LIST = [
474 translation_key=
"successful_commands",
475 translation_placeholders={
"direction":
"RX"},
476 state_class=SensorStateClass.TOTAL,
480 translation_key=
"successful_commands",
481 translation_placeholders={
"direction":
"TX"},
482 state_class=SensorStateClass.TOTAL,
485 key=
"commands_dropped_rx",
486 translation_key=
"commands_dropped",
487 translation_placeholders={
"direction":
"RX"},
488 state_class=SensorStateClass.TOTAL,
491 key=
"commands_dropped_tx",
492 translation_key=
"commands_dropped",
493 translation_placeholders={
"direction":
"TX"},
494 state_class=SensorStateClass.TOTAL,
497 key=
"timeout_response",
498 translation_key=
"timeout_response",
499 state_class=SensorStateClass.TOTAL,
503 translation_key=
"rtt",
504 native_unit_of_measurement=UnitOfTime.MILLISECONDS,
505 device_class=SensorDeviceClass.DURATION,
506 state_class=SensorStateClass.MEASUREMENT,
510 translation_key=
"rssi",
511 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
512 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
513 state_class=SensorStateClass.MEASUREMENT,
517 translation_key=
"last_seen",
518 device_class=SensorDeviceClass.TIMESTAMP,
519 entity_registry_enabled_default=
True,
523 NODE_STATISTICS_KEY_MAP: dict[str, str] = {
524 "commands_rx":
"commandsRX",
525 "commands_tx":
"commandsTX",
526 "commands_dropped_rx":
"commandsDroppedRX",
527 "commands_dropped_tx":
"commandsDroppedTX",
528 "timeout_response":
"timeoutResponse",
531 "last_seen":
"lastSeen",
536 data: NumericSensorDataTemplateData,
537 ) -> SensorEntityDescription:
538 """Return the entity description for the given data."""
539 data_description_key = data.entity_description_key
or ""
540 data_unit = data.unit_of_measurement
or ""
541 return ENTITY_DESCRIPTION_KEY_DEVICE_CLASS_MAP.get(
542 (data_description_key, data_unit),
543 ENTITY_DESCRIPTION_KEY_MAP.get(
544 data_description_key,
546 key=
"base_sensor", native_unit_of_measurement=data.unit_of_measurement
554 config_entry: ConfigEntry,
555 async_add_entities: AddEntitiesCallback,
557 """Set up Z-Wave sensor from config entry."""
558 client: ZwaveClient = config_entry.runtime_data[DATA_CLIENT]
559 driver = client.driver
560 assert driver
is not None
563 def async_add_sensor(info: ZwaveDiscoveryInfo) ->
None:
564 """Add Z-Wave Sensor."""
565 entities: list[ZWaveBaseEntity] = []
567 if info.platform_data:
568 data: NumericSensorDataTemplateData = info.platform_data
574 if info.platform_hint ==
"numeric_sensor":
581 data.unit_of_measurement,
584 elif info.platform_hint ==
"notification":
591 elif info.platform_hint ==
"config_parameter":
594 config_entry, driver, info, entity_description
597 elif info.platform_hint ==
"meter":
602 entities.append(
ZwaveSensor(config_entry, driver, info, entity_description))
607 def async_add_controller_status_sensor() -> None:
608 """Add controller status sensor."""
612 def async_add_node_status_sensor(node: ZwaveNode) ->
None:
613 """Add node status sensor."""
617 def async_add_statistics_sensors(node: ZwaveNode) ->
None:
618 """Add statistics sensors."""
623 CONTROLLER_STATISTICS_KEY_MAP
624 if driver.controller.own_node == node
625 else NODE_STATISTICS_KEY_MAP,
632 driver.controller
if driver.controller.own_node == node
else node,
635 for entity_description
in (
636 ENTITY_DESCRIPTION_CONTROLLER_STATISTICS_LIST
637 if driver.controller.own_node == node
638 else ENTITY_DESCRIPTION_NODE_STATISTICS_LIST
643 config_entry.async_on_unload(
646 f
"{DOMAIN}_{config_entry.entry_id}_add_{SENSOR_DOMAIN}",
651 config_entry.async_on_unload(
654 f
"{DOMAIN}_{config_entry.entry_id}_add_controller_status_sensor",
655 async_add_controller_status_sensor,
659 config_entry.async_on_unload(
662 f
"{DOMAIN}_{config_entry.entry_id}_add_node_status_sensor",
663 async_add_node_status_sensor,
667 config_entry.async_on_unload(
670 f
"{DOMAIN}_{config_entry.entry_id}_add_statistics_sensors",
671 async_add_statistics_sensors,
675 platform = entity_platform.async_get_current_platform()
676 platform.async_register_entity_service(
679 vol.Optional(ATTR_METER_TYPE): vol.Coerce(int),
680 vol.Optional(ATTR_VALUE): vol.Coerce(int),
687 """Basic Representation of a Z-Wave sensor."""
691 config_entry: ConfigEntry,
693 info: ZwaveDiscoveryInfo,
694 entity_description: SensorEntityDescription,
695 unit_of_measurement: str |
None =
None,
697 """Initialize a ZWaveSensorBase entity."""
699 super().
__init__(config_entry, driver, info)
704 if not entity_description.name
or entity_description.name
is UNDEFINED:
709 """Return state of the sensor."""
710 key =
str(self.
infoinfo.primary_value.value)
711 if key
not in self.
infoinfo.primary_value.metadata.states:
712 return self.
infoinfo.primary_value.value
713 return str(self.
infoinfo.primary_value.metadata.states[key])
717 """Return unit of measurement the value is expressed in."""
718 if (unit := super().native_unit_of_measurement)
is not None:
720 if self.
infoinfo.primary_value.metadata.unit
is None:
722 return str(self.
infoinfo.primary_value.metadata.unit)
726 """Representation of a Z-Wave Numeric sensor."""
730 config_entry: ConfigEntry,
732 info: ZwaveDiscoveryInfo,
733 entity_description: SensorEntityDescription,
734 unit_of_measurement: str |
None =
None,
736 """Initialize a ZWaveBasicSensor entity."""
738 config_entry, driver, info, entity_description, unit_of_measurement
740 if self.
infoinfo.primary_value.command_class == CommandClass.BASIC:
742 include_value_name=
True, alternate_value_name=
"Basic"
747 """Handle scale changes for this value on value updated event."""
754 """Return state of the sensor."""
755 if self.
infoinfo.primary_value.value
is None:
757 return float(self.
infoinfo.primary_value.value)
761 """Representation of a Z-Wave Meter CC sensor."""
765 """Return extra state attributes."""
766 meter_type = get_meter_type(self.
infoinfo.primary_value)
768 ATTR_METER_TYPE: meter_type.value,
769 ATTR_METER_TYPE_NAME: meter_type.name,
773 self, meter_type: int |
None =
None, value: int |
None =
None
775 """Reset meter(s) on device."""
776 node = self.
infoinfo.node
777 endpoint = self.
infoinfo.primary_value.endpoint
or 0
779 if meter_type
is not None:
780 options[RESET_METER_OPTION_TYPE] = meter_type
781 if value
is not None:
782 options[RESET_METER_OPTION_TARGET_VALUE] = value
783 args = [options]
if options
else []
785 await node.endpoints[endpoint].async_invoke_cc_api(
786 CommandClass.METER,
"reset", *args, wait_for_result=
False
788 except BaseZwaveJSServerError
as err:
790 f
"Failed to reset meters on node {node} endpoint {endpoint}: {err}"
793 "Meters on node %s endpoint %s reset with the following options: %s",
801 """Representation of a Z-Wave Numeric sensor with multiple states."""
805 config_entry: ConfigEntry,
807 info: ZwaveDiscoveryInfo,
808 entity_description: SensorEntityDescription,
809 unit_of_measurement: str |
None =
None,
811 """Initialize a ZWaveListSensor entity."""
813 config_entry, driver, info, entity_description, unit_of_measurement
821 alternate_value_name=self.
infoinfo.primary_value.property_name,
822 additional_info=[self.
infoinfo.primary_value.property_key_name],
824 if self.
infoinfo.primary_value.metadata.states:
830 """Return the device specific state attributes."""
831 if (value := self.
infoinfo.primary_value.value)
is None:
834 return {ATTR_VALUE: value}
838 """Representation of a Z-Wave config parameter sensor."""
840 _attr_entity_category = EntityCategory.DIAGNOSTIC
844 config_entry: ConfigEntry,
846 info: ZwaveDiscoveryInfo,
847 entity_description: SensorEntityDescription,
848 unit_of_measurement: str |
None =
None,
850 """Initialize a ZWaveConfigParameterSensor entity."""
852 config_entry, driver, info, entity_description, unit_of_measurement
855 property_key_name = self.
infoinfo.primary_value.property_key_name
858 alternate_value_name=self.
infoinfo.primary_value.property_name,
859 additional_info=[property_key_name]
if property_key_name
else None,
864 """Return the device specific state attributes."""
865 if (value := self.
infoinfo.primary_value.value)
is None:
868 return {ATTR_VALUE: value}
872 """Representation of a node status sensor."""
874 _attr_should_poll =
False
875 _attr_entity_category = EntityCategory.DIAGNOSTIC
876 _attr_has_entity_name =
True
877 _attr_translation_key =
"node_status"
880 self, config_entry: ConfigEntry, driver: Driver, node: ZwaveNode
882 """Initialize a generic Z-Wave device entity."""
898 "There is no value to refresh for this entity so the zwave_js.refresh_value"
899 " service won't work for it"
904 """Call when status event is received."""
909 """Call when entity is added."""
911 for evt
in (
"wake up",
"sleep",
"dead",
"alive"):
916 f
"{DOMAIN}_{self.unique_id}_poll_value",
926 f
"{DOMAIN}_{self._base_unique_id}_remove_entity",
935 """Representation of a controller status sensor."""
937 _attr_should_poll =
False
938 _attr_entity_category = EntityCategory.DIAGNOSTIC
939 _attr_has_entity_name =
True
940 _attr_translation_key =
"controller_status"
942 def __init__(self, config_entry: ConfigEntry, driver: Driver) ->
None:
943 """Initialize a generic Z-Wave device entity."""
961 "There is no value to refresh for this entity so the zwave_js.refresh_value"
962 " service won't work for it"
967 """Call when status event is received."""
972 """Call when entity is added."""
978 f
"{DOMAIN}_{self.unique_id}_poll_value",
987 f
"{DOMAIN}_{self._base_unique_id}_remove_entity",
995 """Representation of a node/controller statistics sensor."""
997 entity_description: ZWaveJSStatisticsSensorEntityDescription
998 _attr_should_poll =
False
999 _attr_entity_category = EntityCategory.DIAGNOSTIC
1000 _attr_has_entity_name =
True
1004 config_entry: ConfigEntry,
1006 statistics_src: ZwaveNode | Controller,
1007 description: ZWaveJSStatisticsSensorEntityDescription,
1009 """Initialize a Z-Wave statistics entity."""
1014 statistics_src.own_node
1015 if isinstance(statistics_src, Controller)
1022 self.
_attr_unique_id_attr_unique_id = f
"{self._base_unique_id}.statistics_{description.key}"
1032 "There is no value to refresh for this entity so the zwave_js.refresh_value"
1033 " service won't work for it"
1038 """Call when statistics updated event is received."""
1045 """Call when entity is added."""
1049 f
"{DOMAIN}_{self.unique_id}_poll_value",
1056 f
"{DOMAIN}_{self._base_unique_id}_remove_entity",
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 __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info, SensorEntityDescription entity_description, str|None unit_of_measurement=None)
dict[str, str]|None extra_state_attributes(self)
None async_added_to_hass(self)
None async_poll_value(self, bool _)
None _status_changed(self, dict _)
None __init__(self, ConfigEntry config_entry, Driver driver)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info, SensorEntityDescription entity_description, str|None unit_of_measurement=None)
dict[str, str]|None extra_state_attributes(self)
Mapping[str, int|str]|None extra_state_attributes(self)
None async_reset_meter(self, int|None meter_type=None, int|None value=None)
None _status_changed(self, dict _)
None async_poll_value(self, bool _)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveNode node)
None async_added_to_hass(self)
_attr_native_unit_of_measurement
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info, SensorEntityDescription entity_description, str|None unit_of_measurement=None)
None on_value_update(self)
None async_added_to_hass(self)
None async_poll_value(self, bool _)
None statistics_updated(self, dict event_data)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveNode|Controller statistics_src, ZWaveJSStatisticsSensorEntityDescription description)
str|None native_unit_of_measurement(self)
StateType native_value(self)
_attr_native_unit_of_measurement
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info, SensorEntityDescription entity_description, str|None unit_of_measurement=None)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_remove(self, *bool force_remove=False)
DeviceInfo get_device_info(str coordinates, str name)
bool|NotificationZWaveJSEntityDescription is_valid_notification_binary_sensor(ZwaveDiscoveryInfo info)
str get_valueless_base_unique_id(Driver driver, ZwaveNode node)
None async_migrate_statistics_sensors(HomeAssistant hass, Driver driver, Node node, dict[str, str] key_map)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Any convert_nested_attr(ControllerStatistics|NodeStatistics statistics, str key)
SensorEntityDescription get_entity_description(NumericSensorDataTemplateData data)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)