mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Add stop_cover service for zwave_js (#45805)
This commit is contained in:
parent
9f59515bb8
commit
a8cf377ed7
@ -21,6 +21,8 @@ from .entity import ZWaveBaseEntity
|
|||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
SUPPORT_GARAGE = SUPPORT_OPEN | SUPPORT_CLOSE
|
SUPPORT_GARAGE = SUPPORT_OPEN | SUPPORT_CLOSE
|
||||||
|
PRESS_BUTTON = True
|
||||||
|
RELEASE_BUTTON = False
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@ -77,10 +79,17 @@ class ZWaveCover(ZWaveBaseEntity, CoverEntity):
|
|||||||
|
|
||||||
async def async_open_cover(self, **kwargs: Any) -> None:
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
"""Open the cover."""
|
"""Open the cover."""
|
||||||
target_value = self.get_zwave_value("targetValue")
|
target_value = self.get_zwave_value("Open")
|
||||||
await self.info.node.async_set_value(target_value, 99)
|
await self.info.node.async_set_value(target_value, PRESS_BUTTON)
|
||||||
|
|
||||||
async def async_close_cover(self, **kwargs: Any) -> None:
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||||
"""Close cover."""
|
"""Close cover."""
|
||||||
target_value = self.get_zwave_value("targetValue")
|
target_value = self.get_zwave_value("Close")
|
||||||
await self.info.node.async_set_value(target_value, 0)
|
await self.info.node.async_set_value(target_value, PRESS_BUTTON)
|
||||||
|
|
||||||
|
async def async_stop_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Stop cover."""
|
||||||
|
target_value = self.get_zwave_value("Open")
|
||||||
|
await self.info.node.async_set_value(target_value, RELEASE_BUTTON)
|
||||||
|
target_value = self.get_zwave_value("Close")
|
||||||
|
await self.info.node.async_set_value(target_value, RELEASE_BUTTON)
|
||||||
|
@ -95,21 +95,65 @@ async def test_cover(hass, client, chain_actuator_zws12, integration):
|
|||||||
"commandClassName": "Multilevel Switch",
|
"commandClassName": "Multilevel Switch",
|
||||||
"commandClass": 38,
|
"commandClass": 38,
|
||||||
"endpoint": 0,
|
"endpoint": 0,
|
||||||
"property": "targetValue",
|
"property": "Open",
|
||||||
"propertyName": "targetValue",
|
"propertyName": "Open",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"label": "Target value",
|
"type": "boolean",
|
||||||
"max": 99,
|
|
||||||
"min": 0,
|
|
||||||
"type": "number",
|
|
||||||
"readable": True,
|
"readable": True,
|
||||||
"writeable": True,
|
"writeable": True,
|
||||||
"label": "Target value",
|
"label": "Perform a level change (Open)",
|
||||||
|
"ccSpecific": {"switchType": 3},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert args["value"] == 99
|
assert args["value"]
|
||||||
|
|
||||||
client.async_send_command.reset_mock()
|
client.async_send_command.reset_mock()
|
||||||
|
# Test stop after opening
|
||||||
|
await hass.services.async_call(
|
||||||
|
"cover",
|
||||||
|
"stop_cover",
|
||||||
|
{"entity_id": WINDOW_COVER_ENTITY},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(client.async_send_command.call_args_list) == 2
|
||||||
|
open_args = client.async_send_command.call_args_list[0][0][0]
|
||||||
|
assert open_args["command"] == "node.set_value"
|
||||||
|
assert open_args["nodeId"] == 6
|
||||||
|
assert open_args["valueId"] == {
|
||||||
|
"commandClassName": "Multilevel Switch",
|
||||||
|
"commandClass": 38,
|
||||||
|
"endpoint": 0,
|
||||||
|
"property": "Open",
|
||||||
|
"propertyName": "Open",
|
||||||
|
"metadata": {
|
||||||
|
"type": "boolean",
|
||||||
|
"readable": True,
|
||||||
|
"writeable": True,
|
||||||
|
"label": "Perform a level change (Open)",
|
||||||
|
"ccSpecific": {"switchType": 3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert not open_args["value"]
|
||||||
|
|
||||||
|
close_args = client.async_send_command.call_args_list[1][0][0]
|
||||||
|
assert close_args["command"] == "node.set_value"
|
||||||
|
assert close_args["nodeId"] == 6
|
||||||
|
assert close_args["valueId"] == {
|
||||||
|
"commandClassName": "Multilevel Switch",
|
||||||
|
"commandClass": 38,
|
||||||
|
"endpoint": 0,
|
||||||
|
"property": "Close",
|
||||||
|
"propertyName": "Close",
|
||||||
|
"metadata": {
|
||||||
|
"type": "boolean",
|
||||||
|
"readable": True,
|
||||||
|
"writeable": True,
|
||||||
|
"label": "Perform a level change (Close)",
|
||||||
|
"ccSpecific": {"switchType": 3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert not close_args["value"]
|
||||||
|
|
||||||
# Test position update from value updated event
|
# Test position update from value updated event
|
||||||
event = Event(
|
event = Event(
|
||||||
@ -130,6 +174,7 @@ async def test_cover(hass, client, chain_actuator_zws12, integration):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
node.receive_event(event)
|
node.receive_event(event)
|
||||||
|
client.async_send_command.reset_mock()
|
||||||
|
|
||||||
state = hass.states.get(WINDOW_COVER_ENTITY)
|
state = hass.states.get(WINDOW_COVER_ENTITY)
|
||||||
assert state.state == "open"
|
assert state.state == "open"
|
||||||
@ -141,7 +186,6 @@ async def test_cover(hass, client, chain_actuator_zws12, integration):
|
|||||||
{"entity_id": WINDOW_COVER_ENTITY},
|
{"entity_id": WINDOW_COVER_ENTITY},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(client.async_send_command.call_args_list) == 1
|
assert len(client.async_send_command.call_args_list) == 1
|
||||||
args = client.async_send_command.call_args[0][0]
|
args = client.async_send_command.call_args[0][0]
|
||||||
assert args["command"] == "node.set_value"
|
assert args["command"] == "node.set_value"
|
||||||
@ -150,19 +194,66 @@ async def test_cover(hass, client, chain_actuator_zws12, integration):
|
|||||||
"commandClassName": "Multilevel Switch",
|
"commandClassName": "Multilevel Switch",
|
||||||
"commandClass": 38,
|
"commandClass": 38,
|
||||||
"endpoint": 0,
|
"endpoint": 0,
|
||||||
"property": "targetValue",
|
"property": "Close",
|
||||||
"propertyName": "targetValue",
|
"propertyName": "Close",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"label": "Target value",
|
"type": "boolean",
|
||||||
"max": 99,
|
|
||||||
"min": 0,
|
|
||||||
"type": "number",
|
|
||||||
"readable": True,
|
"readable": True,
|
||||||
"writeable": True,
|
"writeable": True,
|
||||||
"label": "Target value",
|
"label": "Perform a level change (Close)",
|
||||||
|
"ccSpecific": {"switchType": 3},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert args["value"] == 0
|
assert args["value"]
|
||||||
|
|
||||||
|
client.async_send_command.reset_mock()
|
||||||
|
|
||||||
|
# Test stop after closing
|
||||||
|
await hass.services.async_call(
|
||||||
|
"cover",
|
||||||
|
"stop_cover",
|
||||||
|
{"entity_id": WINDOW_COVER_ENTITY},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(client.async_send_command.call_args_list) == 2
|
||||||
|
open_args = client.async_send_command.call_args_list[0][0][0]
|
||||||
|
assert open_args["command"] == "node.set_value"
|
||||||
|
assert open_args["nodeId"] == 6
|
||||||
|
assert open_args["valueId"] == {
|
||||||
|
"commandClassName": "Multilevel Switch",
|
||||||
|
"commandClass": 38,
|
||||||
|
"endpoint": 0,
|
||||||
|
"property": "Open",
|
||||||
|
"propertyName": "Open",
|
||||||
|
"metadata": {
|
||||||
|
"type": "boolean",
|
||||||
|
"readable": True,
|
||||||
|
"writeable": True,
|
||||||
|
"label": "Perform a level change (Open)",
|
||||||
|
"ccSpecific": {"switchType": 3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert not open_args["value"]
|
||||||
|
|
||||||
|
close_args = client.async_send_command.call_args_list[1][0][0]
|
||||||
|
assert close_args["command"] == "node.set_value"
|
||||||
|
assert close_args["nodeId"] == 6
|
||||||
|
assert close_args["valueId"] == {
|
||||||
|
"commandClassName": "Multilevel Switch",
|
||||||
|
"commandClass": 38,
|
||||||
|
"endpoint": 0,
|
||||||
|
"property": "Close",
|
||||||
|
"propertyName": "Close",
|
||||||
|
"metadata": {
|
||||||
|
"type": "boolean",
|
||||||
|
"readable": True,
|
||||||
|
"writeable": True,
|
||||||
|
"label": "Perform a level change (Close)",
|
||||||
|
"ccSpecific": {"switchType": 3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert not close_args["value"]
|
||||||
|
|
||||||
client.async_send_command.reset_mock()
|
client.async_send_command.reset_mock()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user