Skip to content

Commit

Permalink
Z-Wave JS: Use start/stop level change to open/close Window Covering …
Browse files Browse the repository at this point in the history
…CC covers
  • Loading branch information
AlCalzone committed Sep 12, 2024
1 parent ba7f363 commit 1199e80
Show file tree
Hide file tree
Showing 4 changed files with 428 additions and 0 deletions.
31 changes: 31 additions & 0 deletions homeassistant/components/zwave_js/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from zwave_js_server.const.command_class.window_covering import (
NO_POSITION_PROPERTY_KEYS,
NO_POSITION_SUFFIX,
WINDOW_COVERING_LEVEL_CHANGE_DOWN_PROPERTY,
WINDOW_COVERING_LEVEL_CHANGE_UP_PROPERTY,
SlatStates,
)
Expand Down Expand Up @@ -341,6 +342,14 @@ def __init__(
super().__init__(config_entry, driver, info)
pos_value: ZwaveValue | None = None
tilt_value: ZwaveValue | None = None
self._up_value: ZwaveValue | None = self.get_zwave_value(
WINDOW_COVERING_LEVEL_CHANGE_UP_PROPERTY,
value_property_key=info.primary_value.property_key,
)
self._down_value: ZwaveValue | None = self.get_zwave_value(
WINDOW_COVERING_LEVEL_CHANGE_DOWN_PROPERTY,
value_property_key=info.primary_value.property_key,
)

# If primary value is for position, we have to search for a tilt value
if info.primary_value.property_key in COVER_POSITION_PROPERTY_KEYS:
Expand Down Expand Up @@ -402,6 +411,28 @@ def _tilt_range(self) -> int:
"""Return range of valid tilt positions."""
return abs(SlatStates.CLOSED_2 - SlatStates.CLOSED_1)

async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
if self._up_value:
await self._async_set_value(self._up_value, True)
else:
await super().async_open_cover(**kwargs)

async def async_close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
if self._down_value:
await self._async_set_value(self._down_value, True)
else:
await super().async_close_cover(**kwargs)

async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""
if self._up_value:
# It does not matter if the up or down value is used
await self._async_set_value(self._up_value, False)
else:
await super().async_stop_cover(**kwargs)


class ZwaveMotorizedBarrier(ZWaveBaseEntity, CoverEntity):
"""Representation of a Z-Wave motorized barrier device."""
Expand Down
16 changes: 16 additions & 0 deletions tests/components/zwave_js/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ def basic_cc_sensor_state_fixture():
return json.loads(load_fixture("zwave_js/basic_cc_sensor_state.json"))


@pytest.fixture(name="window_covering_outbound_bottom_state", scope="package")
def window_covering_outbound_bottom_state_fixture():
"""Load node with Window Covering CC fixture data, with only the outbound bottom position supported."""
return json.loads(load_fixture("zwave_js/window_covering_outbound_bottom.json"))


# model fixtures


Expand Down Expand Up @@ -1161,3 +1167,13 @@ def basic_cc_sensor_fixture(client, basic_cc_sensor_state):
node = Node(client, copy.deepcopy(basic_cc_sensor_state))
client.driver.controller.nodes[node.node_id] = node
return node


@pytest.fixture(name="window_covering_outbound_bottom")
def window_covering_outbound_bottom_fixture(
client, window_covering_outbound_bottom_state
):
"""Load node with Window Covering CC fixture data, with only the outbound bottom position supported."""
node = Node(client, copy.deepcopy(window_covering_outbound_bottom_state))
client.driver.controller.nodes[node.node_id] = node
return node
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
{
"nodeId": 2,
"index": 0,
"status": 4,
"ready": true,
"isListening": true,
"isRouting": true,
"isSecure": false,
"interviewAttempts": 1,
"isFrequentListening": false,
"maxDataRate": 100000,
"supportedDataRates": [40000, 9600, 100000],
"protocolVersion": 3,
"supportsBeaming": true,
"supportsSecurity": false,
"nodeType": 1,
"deviceClass": {
"basic": {
"key": 4,
"label": "Routing End Node"
},
"generic": {
"key": 6,
"label": "Appliance"
},
"specific": {
"key": 1,
"label": "General Appliance"
}
},
"interviewStage": "Complete",
"statistics": {
"commandsTX": 8,
"commandsRX": 5,
"commandsDroppedRX": 0,
"commandsDroppedTX": 0,
"timeoutResponse": 2,
"rtt": 96.3,
"lastSeen": "2024-09-12T11:46:43.065Z"
},
"highestSecurityClass": -1,
"isControllerNode": false,
"keepAwake": false,
"lastSeen": "2024-09-12T11:46:43.065Z",
"protocol": 0,
"values": [
{
"endpoint": 0,
"commandClass": 106,
"commandClassName": "Window Covering",
"property": "levelChangeUp",
"propertyKey": 13,
"propertyName": "levelChangeUp",
"propertyKeyName": "Outbound Bottom",
"ccVersion": 1,
"metadata": {
"type": "boolean",
"readable": false,
"writeable": true,
"label": "Open - Outbound Bottom",
"ccSpecific": {
"parameter": 13
},
"valueChangeOptions": ["transitionDuration"],
"states": {
"true": "Start",
"false": "Stop"
},
"stateful": true,
"secret": false
},
"value": true
},
{
"endpoint": 0,
"commandClass": 106,
"commandClassName": "Window Covering",
"property": "levelChangeDown",
"propertyKey": 13,
"propertyName": "levelChangeDown",
"propertyKeyName": "Outbound Bottom",
"ccVersion": 1,
"metadata": {
"type": "boolean",
"readable": false,
"writeable": true,
"label": "Close - Outbound Bottom",
"ccSpecific": {
"parameter": 13
},
"valueChangeOptions": ["transitionDuration"],
"states": {
"true": "Start",
"false": "Stop"
},
"stateful": true,
"secret": false
},
"value": true
},
{
"endpoint": 0,
"commandClass": 106,
"commandClassName": "Window Covering",
"property": "targetValue",
"propertyKey": 13,
"propertyName": "targetValue",
"propertyKeyName": "Outbound Bottom",
"ccVersion": 1,
"metadata": {
"type": "number",
"readable": true,
"writeable": true,
"label": "Target value - Outbound Bottom",
"ccSpecific": {
"parameter": 13
},
"valueChangeOptions": ["transitionDuration"],
"min": 0,
"max": 99,
"states": {
"0": "Closed",
"99": "Open"
},
"stateful": true,
"secret": false
},
"value": 52
},
{
"endpoint": 0,
"commandClass": 106,
"commandClassName": "Window Covering",
"property": "currentValue",
"propertyKey": 13,
"propertyName": "currentValue",
"propertyKeyName": "Outbound Bottom",
"ccVersion": 1,
"metadata": {
"type": "number",
"readable": true,
"writeable": false,
"label": "Current value - Outbound Bottom",
"ccSpecific": {
"parameter": 13
},
"min": 0,
"max": 99,
"states": {
"0": "Closed",
"99": "Open"
},
"stateful": true,
"secret": false
},
"value": 52
},
{
"endpoint": 0,
"commandClass": 106,
"commandClassName": "Window Covering",
"property": "duration",
"propertyKey": 13,
"propertyName": "duration",
"propertyKeyName": "Outbound Bottom",
"ccVersion": 1,
"metadata": {
"type": "duration",
"readable": true,
"writeable": false,
"label": "Remaining duration - Outbound Bottom",
"ccSpecific": {
"parameter": 13
},
"stateful": true,
"secret": false
}
},
{
"endpoint": 0,
"commandClass": 134,
"commandClassName": "Version",
"property": "firmwareVersions",
"propertyName": "firmwareVersions",
"ccVersion": 1,
"metadata": {
"type": "string[]",
"readable": true,
"writeable": false,
"label": "Z-Wave chip firmware versions",
"stateful": true,
"secret": false
}
},
{
"endpoint": 0,
"commandClass": 134,
"commandClassName": "Version",
"property": "libraryType",
"propertyName": "libraryType",
"ccVersion": 1,
"metadata": {
"type": "number",
"readable": true,
"writeable": false,
"label": "Library type",
"states": {
"0": "Unknown",
"1": "Static Controller",
"2": "Controller",
"3": "Enhanced Slave",
"4": "Slave",
"5": "Installer",
"6": "Routing Slave",
"7": "Bridge Controller",
"8": "Device under Test",
"9": "N/A",
"10": "AV Remote",
"11": "AV Device"
},
"stateful": true,
"secret": false
}
},
{
"endpoint": 0,
"commandClass": 134,
"commandClassName": "Version",
"property": "protocolVersion",
"propertyName": "protocolVersion",
"ccVersion": 1,
"metadata": {
"type": "string",
"readable": true,
"writeable": false,
"label": "Z-Wave protocol version",
"stateful": true,
"secret": false
}
}
],
"endpoints": [
{
"nodeId": 2,
"index": 0,
"deviceClass": {
"basic": {
"key": 4,
"label": "Routing End Node"
},
"generic": {
"key": 6,
"label": "Appliance"
},
"specific": {
"key": 1,
"label": "General Appliance"
}
},
"commandClasses": [
{
"id": 134,
"name": "Version",
"version": 1,
"isSecure": false
},
{
"id": 108,
"name": "Supervision",
"version": 1,
"isSecure": false
},
{
"id": 106,
"name": "Window Covering",
"version": 1,
"isSecure": false
}
]
}
]
}
Loading

0 comments on commit 1199e80

Please sign in to comment.