mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 05:26:47 +00:00
Add cover platform to zwave js (#45193)
This commit is contained in:
189
tests/components/zwave_js/test_cover.py
Normal file
189
tests/components/zwave_js/test_cover.py
Normal file
@@ -0,0 +1,189 @@
|
||||
"""Test the Z-Wave JS cover platform."""
|
||||
from zwave_js_server.event import Event
|
||||
|
||||
from homeassistant.components.cover import ATTR_CURRENT_POSITION
|
||||
|
||||
WINDOW_COVER_ENTITY = "cover.zws_12_current_value"
|
||||
|
||||
|
||||
async def test_cover(hass, client, chain_actuator_zws12, integration):
|
||||
"""Test the light entity."""
|
||||
node = chain_actuator_zws12
|
||||
state = hass.states.get(WINDOW_COVER_ENTITY)
|
||||
|
||||
assert state
|
||||
assert state.state == "closed"
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
|
||||
# Test setting position
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_position",
|
||||
{"entity_id": WINDOW_COVER_ENTITY, "position": 50},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
args = client.async_send_command.call_args[0][0]
|
||||
assert args["command"] == "node.set_value"
|
||||
assert args["nodeId"] == 6
|
||||
assert args["valueId"] == {
|
||||
"commandClassName": "Multilevel Switch",
|
||||
"commandClass": 38,
|
||||
"endpoint": 0,
|
||||
"property": "targetValue",
|
||||
"propertyName": "targetValue",
|
||||
"metadata": {
|
||||
"label": "Target value",
|
||||
"max": 99,
|
||||
"min": 0,
|
||||
"type": "number",
|
||||
"readable": True,
|
||||
"writeable": True,
|
||||
"label": "Target value",
|
||||
},
|
||||
}
|
||||
assert args["value"] == 50
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
# Test setting position
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_position",
|
||||
{"entity_id": WINDOW_COVER_ENTITY, "position": 0},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
args = client.async_send_command.call_args[0][0]
|
||||
assert args["command"] == "node.set_value"
|
||||
assert args["nodeId"] == 6
|
||||
assert args["valueId"] == {
|
||||
"commandClassName": "Multilevel Switch",
|
||||
"commandClass": 38,
|
||||
"endpoint": 0,
|
||||
"property": "targetValue",
|
||||
"propertyName": "targetValue",
|
||||
"metadata": {
|
||||
"label": "Target value",
|
||||
"max": 99,
|
||||
"min": 0,
|
||||
"type": "number",
|
||||
"readable": True,
|
||||
"writeable": True,
|
||||
"label": "Target value",
|
||||
},
|
||||
}
|
||||
assert args["value"] == 0
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
# Test opening
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"open_cover",
|
||||
{"entity_id": WINDOW_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
args = client.async_send_command.call_args[0][0]
|
||||
assert args["command"] == "node.set_value"
|
||||
assert args["nodeId"] == 6
|
||||
assert args["valueId"] == {
|
||||
"commandClassName": "Multilevel Switch",
|
||||
"commandClass": 38,
|
||||
"endpoint": 0,
|
||||
"property": "targetValue",
|
||||
"propertyName": "targetValue",
|
||||
"metadata": {
|
||||
"label": "Target value",
|
||||
"max": 99,
|
||||
"min": 0,
|
||||
"type": "number",
|
||||
"readable": True,
|
||||
"writeable": True,
|
||||
"label": "Target value",
|
||||
},
|
||||
}
|
||||
assert args["value"] == 99
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
# Test position update from value updated event
|
||||
event = Event(
|
||||
type="value updated",
|
||||
data={
|
||||
"source": "node",
|
||||
"event": "value updated",
|
||||
"nodeId": 6,
|
||||
"args": {
|
||||
"commandClassName": "Multilevel Switch",
|
||||
"commandClass": 38,
|
||||
"endpoint": 0,
|
||||
"property": "currentValue",
|
||||
"newValue": 99,
|
||||
"prevValue": 0,
|
||||
"propertyName": "currentValue",
|
||||
},
|
||||
},
|
||||
)
|
||||
node.receive_event(event)
|
||||
|
||||
state = hass.states.get(WINDOW_COVER_ENTITY)
|
||||
assert state.state == "open"
|
||||
|
||||
# Test closing
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"close_cover",
|
||||
{"entity_id": WINDOW_COVER_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
args = client.async_send_command.call_args[0][0]
|
||||
assert args["command"] == "node.set_value"
|
||||
assert args["nodeId"] == 6
|
||||
assert args["valueId"] == {
|
||||
"commandClassName": "Multilevel Switch",
|
||||
"commandClass": 38,
|
||||
"endpoint": 0,
|
||||
"property": "targetValue",
|
||||
"propertyName": "targetValue",
|
||||
"metadata": {
|
||||
"label": "Target value",
|
||||
"max": 99,
|
||||
"min": 0,
|
||||
"type": "number",
|
||||
"readable": True,
|
||||
"writeable": True,
|
||||
"label": "Target value",
|
||||
},
|
||||
}
|
||||
assert args["value"] == 0
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
event = Event(
|
||||
type="value updated",
|
||||
data={
|
||||
"source": "node",
|
||||
"event": "value updated",
|
||||
"nodeId": 6,
|
||||
"args": {
|
||||
"commandClassName": "Multilevel Switch",
|
||||
"commandClass": 38,
|
||||
"endpoint": 0,
|
||||
"property": "currentValue",
|
||||
"newValue": 0,
|
||||
"prevValue": 0,
|
||||
"propertyName": "currentValue",
|
||||
},
|
||||
},
|
||||
)
|
||||
node.receive_event(event)
|
||||
|
||||
state = hass.states.get(WINDOW_COVER_ENTITY)
|
||||
assert state.state == "closed"
|
||||
Reference in New Issue
Block a user