1 """Support for Z-Wave controls using the number platform."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from typing
import Any, cast
8 from zwave_js_server.client
import Client
as ZwaveClient
9 from zwave_js_server.const
import TARGET_VALUE_PROPERTY
10 from zwave_js_server.model.driver
import Driver
11 from zwave_js_server.model.value
import Value
21 from .const
import ATTR_RESERVED_VALUES, 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 Number entity from Config Entry."""
34 client: ZwaveClient = config_entry.runtime_data[DATA_CLIENT]
37 def async_add_number(info: ZwaveDiscoveryInfo) ->
None:
38 """Add Z-Wave number entity."""
39 driver = client.driver
40 assert driver
is not None
41 entities: list[ZWaveBaseEntity] = []
42 if info.platform_hint ==
"volume":
44 elif info.platform_hint ==
"config_parameter":
52 config_entry.async_on_unload(
55 f
"{DOMAIN}_{config_entry.entry_id}_add_{NUMBER_DOMAIN}",
62 """Representation of a Z-Wave number entity."""
65 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
67 """Initialize a ZwaveNumberEntity entity."""
68 super().
__init__(config_entry, driver, info)
70 if self.
infoinfo.primary_value.metadata.writeable:
77 include_value_name=
True, alternate_value_name=info.platform_hint
82 """Return the minimum value."""
83 min_ = self.
infoinfo.primary_value.metadata.min
84 return float(0
if min_
is None else min_)
88 """Return the maximum value."""
89 max_ = self.
infoinfo.primary_value.metadata.max
90 return float(255
if max_
is None else max_)
94 """Return the entity value."""
95 value = self.
infoinfo.primary_value.value
96 return None if value
is None else float(value)
100 """Return the unit of measurement of this entity, if any."""
101 unit = self.
infoinfo.primary_value.metadata.unit
102 return None if unit
is None else str(unit)
106 if (target_value := self.
_target_value_target_value)
is None:
112 """Representation of a Z-Wave config parameter number."""
114 _attr_entity_category = EntityCategory.CONFIG
117 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
119 """Initialize a ZWaveConfigParameterNumber entity."""
120 super().
__init__(config_entry, driver, info)
122 property_key_name = self.
infoinfo.primary_value.property_key_name
125 alternate_value_name=self.
infoinfo.primary_value.property_name,
126 additional_info=[property_key_name]
if property_key_name
else None,
131 """Return extra state attributes for entity."""
132 if not self.
infoinfo.primary_value.metadata.states:
135 ATTR_RESERVED_VALUES: {
136 int(k): v
for k, v
in self.
infoinfo.primary_value.metadata.states.items()
142 """Representation of a volume number entity."""
145 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
147 """Initialize a ZwaveVolumeNumberEntity entity."""
148 super().
__init__(config_entry, driver, info)
149 max_value = cast(int, self.
infoinfo.primary_value.metadata.max)
150 min_value = cast(int, self.
infoinfo.primary_value.metadata.min)
161 """Return the entity value."""
162 if self.
infoinfo.primary_value.value
is None:
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)
Mapping[str, Any]|None extra_state_attributes(self)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
float native_max_value(self)
float native_min_value(self)
float|None native_value(self)
None async_set_native_value(self, float value)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
str|None native_unit_of_measurement(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)