Add zwave_js set_config_parameter WS API command (#46910)
* add WS API command * handle error scenario better * fixes and remove duplicate catch * make elif statement more compact * fix conflict * switch to str(err)
This commit is contained in:
parent
580d25c622
commit
1cecf229b9
2 changed files with 182 additions and 1 deletions
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
|||
|
||||
from zwave_js_server.const import LogLevel
|
||||
from zwave_js_server.event import Event
|
||||
from zwave_js_server.exceptions import InvalidNewValue, NotFoundError, SetValueFailed
|
||||
|
||||
from homeassistant.components.zwave_js.api import (
|
||||
CONFIG,
|
||||
|
@ -15,7 +16,10 @@ from homeassistant.components.zwave_js.api import (
|
|||
LEVEL,
|
||||
LOG_TO_FILE,
|
||||
NODE_ID,
|
||||
PROPERTY,
|
||||
PROPERTY_KEY,
|
||||
TYPE,
|
||||
VALUE,
|
||||
)
|
||||
from homeassistant.components.zwave_js.const import DOMAIN
|
||||
from homeassistant.helpers.device_registry import async_get_registry
|
||||
|
@ -186,6 +190,125 @@ async def test_remove_node(
|
|||
assert device is None
|
||||
|
||||
|
||||
async def test_set_config_parameter(
|
||||
hass, client, hass_ws_client, multisensor_6, integration
|
||||
):
|
||||
"""Test the set_config_parameter service."""
|
||||
entry = integration
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
client.async_send_command.return_value = {"success": True}
|
||||
|
||||
await ws_client.send_json(
|
||||
{
|
||||
ID: 1,
|
||||
TYPE: "zwave_js/set_config_parameter",
|
||||
ENTRY_ID: entry.entry_id,
|
||||
NODE_ID: 52,
|
||||
PROPERTY: 102,
|
||||
PROPERTY_KEY: 1,
|
||||
VALUE: 1,
|
||||
}
|
||||
)
|
||||
|
||||
msg = await ws_client.receive_json()
|
||||
assert msg["result"]
|
||||
|
||||
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"] == 52
|
||||
assert args["valueId"] == {
|
||||
"commandClassName": "Configuration",
|
||||
"commandClass": 112,
|
||||
"endpoint": 0,
|
||||
"property": 102,
|
||||
"propertyName": "Group 2: Send battery reports",
|
||||
"propertyKey": 1,
|
||||
"metadata": {
|
||||
"type": "number",
|
||||
"readable": True,
|
||||
"writeable": True,
|
||||
"valueSize": 4,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"default": 1,
|
||||
"format": 0,
|
||||
"allowManualEntry": True,
|
||||
"label": "Group 2: Send battery reports",
|
||||
"description": "Include battery information in periodic reports to Group 2",
|
||||
"isFromConfig": True,
|
||||
},
|
||||
"value": 0,
|
||||
}
|
||||
assert args["value"] == 1
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.zwave_js.api.async_set_config_parameter",
|
||||
) as set_param_mock:
|
||||
set_param_mock.side_effect = InvalidNewValue("test")
|
||||
await ws_client.send_json(
|
||||
{
|
||||
ID: 2,
|
||||
TYPE: "zwave_js/set_config_parameter",
|
||||
ENTRY_ID: entry.entry_id,
|
||||
NODE_ID: 52,
|
||||
PROPERTY: 102,
|
||||
PROPERTY_KEY: 1,
|
||||
VALUE: 1,
|
||||
}
|
||||
)
|
||||
|
||||
msg = await ws_client.receive_json()
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 0
|
||||
assert not msg["success"]
|
||||
assert msg["error"]["code"] == "not_supported"
|
||||
assert msg["error"]["message"] == "test"
|
||||
|
||||
set_param_mock.side_effect = NotFoundError("test")
|
||||
await ws_client.send_json(
|
||||
{
|
||||
ID: 3,
|
||||
TYPE: "zwave_js/set_config_parameter",
|
||||
ENTRY_ID: entry.entry_id,
|
||||
NODE_ID: 52,
|
||||
PROPERTY: 102,
|
||||
PROPERTY_KEY: 1,
|
||||
VALUE: 1,
|
||||
}
|
||||
)
|
||||
|
||||
msg = await ws_client.receive_json()
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 0
|
||||
assert not msg["success"]
|
||||
assert msg["error"]["code"] == "not_found"
|
||||
assert msg["error"]["message"] == "test"
|
||||
|
||||
set_param_mock.side_effect = SetValueFailed("test")
|
||||
await ws_client.send_json(
|
||||
{
|
||||
ID: 4,
|
||||
TYPE: "zwave_js/set_config_parameter",
|
||||
ENTRY_ID: entry.entry_id,
|
||||
NODE_ID: 52,
|
||||
PROPERTY: 102,
|
||||
PROPERTY_KEY: 1,
|
||||
VALUE: 1,
|
||||
}
|
||||
)
|
||||
|
||||
msg = await ws_client.receive_json()
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 0
|
||||
assert not msg["success"]
|
||||
assert msg["error"]["code"] == "unknown_error"
|
||||
assert msg["error"]["message"] == "test"
|
||||
|
||||
|
||||
async def test_dump_view(integration, hass_client):
|
||||
"""Test the HTTP dump view."""
|
||||
client = await hass_client()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue