1 """Support for Z-Wave cover devices."""
3 from __future__
import annotations
5 from typing
import Any, cast
7 from zwave_js_server.client
import Client
as ZwaveClient
8 from zwave_js_server.const
import (
9 CURRENT_VALUE_PROPERTY,
10 TARGET_STATE_PROPERTY,
11 TARGET_VALUE_PROPERTY,
13 from zwave_js_server.const.command_class.barrier_operator
import BarrierState
14 from zwave_js_server.const.command_class.multilevel_switch
import (
19 from zwave_js_server.const.command_class.window_covering
import (
20 NO_POSITION_PROPERTY_KEYS,
22 WINDOW_COVERING_LEVEL_CHANGE_DOWN_PROPERTY,
23 WINDOW_COVERING_LEVEL_CHANGE_UP_PROPERTY,
26 from zwave_js_server.model.driver
import Driver
27 from zwave_js_server.model.value
import Value
as ZwaveValue
32 DOMAIN
as COVER_DOMAIN,
43 COVER_POSITION_PROPERTY_KEYS,
44 COVER_TILT_PROPERTY_KEYS,
48 from .discovery
import ZwaveDiscoveryInfo
49 from .discovery_data_template
import CoverTiltDataTemplate
50 from .entity
import ZWaveBaseEntity
57 config_entry: ConfigEntry,
58 async_add_entities: AddEntitiesCallback,
60 """Set up Z-Wave Cover from Config Entry."""
61 client: ZwaveClient = config_entry.runtime_data[DATA_CLIENT]
64 def async_add_cover(info: ZwaveDiscoveryInfo) ->
None:
65 """Add Z-Wave cover."""
66 driver = client.driver
67 assert driver
is not None
68 entities: list[ZWaveBaseEntity] = []
69 if info.platform_hint ==
"window_covering":
71 elif info.platform_hint ==
"motorized_barrier":
73 elif info.platform_hint
and info.platform_hint.endswith(
"tilt"):
79 config_entry.async_on_unload(
82 f
"{DOMAIN}_{config_entry.entry_id}_add_{COVER_DOMAIN}",
89 """Mix-in class for cover with position support."""
91 _current_position_value: ZwaveValue |
None =
None
92 _target_position_value: ZwaveValue |
None =
None
93 _stop_position_value: ZwaveValue |
None =
None
97 current_value: ZwaveValue,
98 target_value: ZwaveValue |
None =
None,
99 stop_value: ZwaveValue |
None =
None,
101 """Set values for position."""
104 | CoverEntityFeature.OPEN
105 | CoverEntityFeature.CLOSE
106 | CoverEntityFeature.SET_POSITION
110 TARGET_VALUE_PROPERTY, value_property_key=current_value.property_key
118 """Convert position in 0-100 scale to closed_value-open_value scale."""
125 """Convert closed_value-open_value scale to position in 0-100 scale."""
132 """Return value that represents fully opened position."""
133 max_ = self.
infoinfo.primary_value.metadata.max
134 return 99
if max_
is None else max_
138 """Return value that represents fully closed position."""
139 min_ = self.
infoinfo.primary_value.metadata.min
140 return 0
if min_
is None else min_
144 """Return range between fully opened and fully closed position."""
149 """Return true if cover is closed."""
156 """Return the current position of cover where 0 means closed and 100 is fully open."""
166 """Move the cover to a specific position."""
174 """Open the cover."""
195 """Mix-in class for cover with tilt support."""
197 _current_tilt_value: ZwaveValue |
None =
None
198 _target_tilt_value: ZwaveValue |
None =
None
199 _stop_tilt_value: ZwaveValue |
None =
None
203 current_value: ZwaveValue,
204 target_value: ZwaveValue |
None =
None,
205 stop_value: ZwaveValue |
None =
None,
207 """Set values for tilt."""
210 | CoverEntityFeature.OPEN_TILT
211 | CoverEntityFeature.CLOSE_TILT
212 | CoverEntityFeature.SET_TILT_POSITION
216 TARGET_VALUE_PROPERTY, value_property_key=current_value.property_key
224 """Convert position in 0-100 scale to closed_value-open_value scale."""
231 """Convert closed_value-open_value scale to position in 0-100 scale."""
236 """Return value that represents fully opened tilt."""
237 max_ = self.
infoinfo.primary_value.metadata.max
238 return 99
if max_
is None else max_
242 """Return value that represents fully closed tilt."""
243 min_ = self.
infoinfo.primary_value.metadata.min
244 return 0
if min_
is None else min_
248 """Return range between fully opened and fully closed tilt."""
253 """Return current position of cover tilt.
255 None is unknown, 0 is closed, 100 is fully open.
262 """Move the cover tilt to a specific position."""
270 """Open the cover tilt."""
275 """Close the cover tilt."""
280 """Stop the cover tilt."""
287 """Representation of a Z-Wave Cover that uses Multilevel Switch CC for position."""
291 config_entry: ConfigEntry,
293 info: ZwaveDiscoveryInfo,
295 """Initialize a ZWaveCover entity."""
296 super().
__init__(config_entry, driver, info)
298 self.
infoinfo.primary_value,
308 if self.
infoinfo.platform_hint
and self.
infoinfo.platform_hint.startswith(
"shutter"):
310 elif self.
infoinfo.platform_hint
and self.
infoinfo.platform_hint.startswith(
"blind"):
312 elif self.
infoinfo.platform_hint
and self.
infoinfo.platform_hint.startswith(
"gate"):
317 """Representation of a Z-Wave cover device with tilt."""
321 config_entry: ConfigEntry,
323 info: ZwaveDiscoveryInfo,
325 """Initialize a ZWaveCover entity."""
326 super().
__init__(config_entry, driver, info)
328 template = cast(CoverTiltDataTemplate, self.
infoinfo.platform_data_template)
330 template.current_tilt_value(self.
infoinfo.platform_data),
331 template.target_tilt_value(self.
infoinfo.platform_data),
336 """Representation of a Z-Wave Window Covering cover device."""
339 self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
342 super().
__init__(config_entry, driver, info)
343 pos_value: ZwaveValue |
None =
None
344 tilt_value: ZwaveValue |
None =
None
348 WINDOW_COVERING_LEVEL_CHANGE_UP_PROPERTY,
349 value_property_key=info.primary_value.property_key,
355 WINDOW_COVERING_LEVEL_CHANGE_DOWN_PROPERTY,
356 value_property_key=info.primary_value.property_key,
361 if info.primary_value.property_key
in COVER_POSITION_PROPERTY_KEYS:
362 pos_value = info.primary_value
366 for property_key
in COVER_TILT_PROPERTY_KEYS
369 CURRENT_VALUE_PROPERTY, value_property_key=property_key
377 tilt_value = info.primary_value
381 for set_values_func, value, set_position_feature
in (
383 (self.
_set_tilt_values_set_tilt_values, tilt_value, CoverEntityFeature.SET_TILT_POSITION),
389 WINDOW_COVERING_LEVEL_CHANGE_UP_PROPERTY,
390 value_property_key=value.property_key,
393 if value.property_key
in NO_POSITION_PROPERTY_KEYS:
397 additional_info: list[str] = [
398 value.property_key_name.removesuffix(f
" {NO_POSITION_SUFFIX}")
400 if value
and value.property_key_name
407 """Return position to open cover tilt."""
408 return SlatStates.OPEN
412 """Return position to close cover tilt."""
413 return SlatStates.CLOSED_1
417 """Return range of valid tilt positions."""
418 return abs(SlatStates.CLOSED_2 - SlatStates.CLOSED_1)
421 """Open the cover."""
425 """Close the cover."""
429 """Stop the cover."""
434 """Representation of a Z-Wave motorized barrier device."""
436 _attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
437 _attr_device_class = CoverDeviceClass.GARAGE
441 config_entry: ConfigEntry,
443 info: ZwaveDiscoveryInfo,
445 """Initialize a ZwaveMotorizedBarrier entity."""
446 super().
__init__(config_entry, driver, info)
450 self.
get_zwave_valueget_zwave_value(TARGET_STATE_PROPERTY, add_to_watched_value_ids=
False),
455 """Return if the cover is opening or not."""
456 if self.
infoinfo.primary_value.value
is None:
458 return bool(self.
infoinfo.primary_value.value == BarrierState.OPENING)
462 """Return if the cover is closing or not."""
463 if self.
infoinfo.primary_value.value
is None:
465 return bool(self.
infoinfo.primary_value.value == BarrierState.CLOSING)
469 """Return if the cover is closed or not."""
470 if self.
infoinfo.primary_value.value
is None:
476 if self.
infoinfo.primary_value.value == BarrierState.STOPPED:
479 return bool(self.
infoinfo.primary_value.value == BarrierState.CLOSED)
482 """Open the garage door."""
486 """Close the garage door."""
current_cover_tilt_position
None async_open_cover(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
int _fully_open_position(self)
None async_set_cover_position(self, **Any kwargs)
int _fully_closed_position(self)
bool|None is_closed(self)
None async_stop_cover(self, **Any kwargs)
int percent_to_zwave_position(self, int value)
int zwave_to_percent_position(self, int value)
None _set_position_values(self, ZwaveValue current_value, ZwaveValue|None target_value=None, ZwaveValue|None stop_value=None)
int _position_range(self)
None async_set_cover_tilt_position(self, **Any kwargs)
int _fully_open_tilt(self)
None async_close_cover_tilt(self, **Any kwargs)
int zwave_to_percent_tilt(self, int value)
int _fully_closed_tilt(self)
None async_stop_cover_tilt(self, **Any kwargs)
None _set_tilt_values(self, ZwaveValue current_value, ZwaveValue|None target_value=None, ZwaveValue|None stop_value=None)
None async_open_cover_tilt(self, **Any kwargs)
int percent_to_zwave_tilt(self, int value)
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)
int _fully_open_tilt(self)
None async_close_cover(self, **Any kwargs)
None async_stop_cover(self, **Any kwargs)
int _fully_closed_tilt(self)
None async_open_cover(self, **Any kwargs)
bool|None is_opening(self)
None async_close_cover(self, **Any kwargs)
bool|None is_closed(self)
bool|None is_closing(self)
None __init__(self, ConfigEntry config_entry, Driver driver, ZwaveDiscoveryInfo info)
None async_open_cover(self, **Any kwargs)
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_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)