Add OZW node config parameters websocket commands (#40527)
* add websocket commands to retrieve and set config parameters for a node * move set_config_parameter into generic function and refactor service and WS API * add payload to return to make service call behave the same way it did before * create response class * update error message to pass tests * move things a bit to reduce LOC * add tests * handle logging errors better and make new response class more generic to prepare for lock user code work * remove unused function parameter * invert check * add additional error checking * refactor a bit to remove repeat code * revert log msg change * one more refactor to create generic get_config_parameters function * change if logic for consistency * fix test * add support to provide bool value in set_config_parameter service call * standardize parameter names on service call * add test coverage * fix tests and message sending * remove unnecessary logging import * fix one test to get missing coverage * update per martin and kpines reviews * remove false assertion * string line length * add support for Decimal config param, remove node instance ID as input, and move helper functions to node.py * cast Decimal appropriately * revert change to support Decimal for config params since they are not supported as a config param type * revert to using error arguments to make next PR for WS lock commands easier * switch to class method and add guard for list Value not being a number * update logic to use new openzwavemqtt util methods * add support for bitsets * use parent exception class * bump openzwavemqtt version, remove node.py from .coveragerc and put file references in the right place * add comment * improve config validation * remove bitset support from config validation * re-add bitset support with some additional tests * move send_result out of try block
This commit is contained in:
1 parent
c777647233
commit
6db4075a23
8 files changed
+357
-104
No files matched your search
@@ -1,5 +1,13 @@
|
||||
"""Test OpenZWave Websocket API."""
|
||||
from openzwavemqtt.const import (
|
||||
ATTR_LABEL,
|
||||
ATTR_OPTIONS,
|
||||
ATTR_POSITION,
|
||||
ATTR_VALUE,
|
||||
ValueType,
|
||||
)
|
||||
|
||||
from homeassistant.components.ozw.const import ATTR_CONFIG_PARAMETER
|
||||
from homeassistant.components.ozw.websocket_api import (
|
||||
ATTR_IS_AWAKE,
|
||||
ATTR_IS_BEAMING,
|
||||
@@ -17,9 +25,15 @@ from homeassistant.components.ozw.websocket_api import (
|
||||
ID,
|
||||
NODE_ID,
|
||||
OZW_INSTANCE,
|
||||
PARAMETER,
|
||||
TYPE,
|
||||
VALUE,
|
||||
)
|
||||
from homeassistant.components.websocket_api.const import (
|
||||
ERR_INVALID_FORMAT,
|
||||
ERR_NOT_FOUND,
|
||||
ERR_NOT_SUPPORTED,
|
||||
)
|
||||
from homeassistant.components.websocket_api.const import ERR_NOT_FOUND
|
||||
|
||||
from .common import MQTTMessage, setup_ozw
|
||||
|
||||
@@ -119,6 +133,149 @@ async def test_websocket_api(hass, generic_data, hass_ws_client):
|
||||
assert result[2][ATTR_IS_AWAKE]
|
||||
assert not result[1][ATTR_IS_FAILED]
|
||||
|
||||
# Test get config parameters
|
||||
await client.send_json({ID: 13, TYPE: "ozw/get_config_parameters", NODE_ID: 39})
|
||||
msg = await client.receive_json()
|
||||
result = msg["result"]
|
||||
assert len(result) == 8
|
||||
for config_param in result:
|
||||
assert config_param["type"] in (
|
||||
ValueType.LIST.value,
|
||||
ValueType.BOOL.value,
|
||||
ValueType.INT.value,
|
||||
ValueType.BYTE.value,
|
||||
ValueType.SHORT.value,
|
||||
ValueType.BITSET.value,
|
||||
)
|
||||
|
||||
# Test set config parameter
|
||||
config_param = result[0]
|
||||
current_val = config_param[ATTR_VALUE]
|
||||
new_val = next(
|
||||
option["Value"]
|
||||
for option in config_param[ATTR_OPTIONS]
|
||||
if option["Label"] != current_val
|
||||
)
|
||||
new_label = next(
|
||||
option["Label"]
|
||||
for option in config_param[ATTR_OPTIONS]
|
||||
if option["Label"] != current_val and option["Value"] != new_val
|
||||
)
|
||||
await client.send_json(
|
||||
{
|
||||
ID: 14,
|
||||
TYPE: "ozw/set_config_parameter",
|
||||
NODE_ID: 39,
|
||||
PARAMETER: config_param[ATTR_CONFIG_PARAMETER],
|
||||
VALUE: new_val,
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
assert msg["success"]
|
||||
await client.send_json(
|
||||
{
|
||||
ID: 15,
|
||||
TYPE: "ozw/set_config_parameter",
|
||||
NODE_ID: 39,
|
||||
PARAMETER: config_param[ATTR_CONFIG_PARAMETER],
|
||||
VALUE: new_label,
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
assert msg["success"]
|
||||
|
||||
# Test OZW Instance not found error
|
||||
await client.send_json(
|
||||
{ID: 16, TYPE: "ozw/get_config_parameters", OZW_INSTANCE: 999, NODE_ID: 1}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
result = msg["error"]
|
||||
assert result["code"] == ERR_NOT_FOUND
|
||||
|
||||
# Test OZW Node not found error
|
||||
await client.send_json(
|
||||
{
|
||||
ID: 18,
|
||||
TYPE: "ozw/set_config_parameter",
|
||||
NODE_ID: 999,
|
||||
PARAMETER: 0,
|
||||
VALUE: "test",
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
result = msg["error"]
|
||||
assert result["code"] == ERR_NOT_FOUND
|
||||
|
||||
# Test parameter not found
|
||||
await client.send_json(
|
||||
{
|
||||
ID: 19,
|
||||
TYPE: "ozw/set_config_parameter",
|
||||
NODE_ID: 39,
|
||||
PARAMETER: 45,
|
||||
VALUE: "test",
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
result = msg["error"]
|
||||
assert result["code"] == ERR_NOT_FOUND
|
||||
|
||||
# Test list value not found
|
||||
await client.send_json(
|
||||
{
|
||||
ID: 20,
|
||||
TYPE: "ozw/set_config_parameter",
|
||||
NODE_ID: 39,
|
||||
PARAMETER: config_param[ATTR_CONFIG_PARAMETER],
|
||||
VALUE: "test",
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
result = msg["error"]
|
||||
assert result["code"] == ERR_NOT_FOUND
|
||||
|
||||
# Test value type invalid
|
||||
await client.send_json(
|
||||
{
|
||||
ID: 21,
|
||||
TYPE: "ozw/set_config_parameter",
|
||||
NODE_ID: 39,
|
||||
PARAMETER: 3,
|
||||
VALUE: 0,
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
result = msg["error"]
|
||||
assert result["code"] == ERR_NOT_SUPPORTED
|
||||
|
||||
# Test invalid bitset format
|
||||
await client.send_json(
|
||||
{
|
||||
ID: 22,
|
||||
TYPE: "ozw/set_config_parameter",
|
||||
NODE_ID: 39,
|
||||
PARAMETER: 3,
|
||||
VALUE: {ATTR_POSITION: 1, ATTR_VALUE: True, ATTR_LABEL: "test"},
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
result = msg["error"]
|
||||
assert result["code"] == ERR_INVALID_FORMAT
|
||||
|
||||
# Test valid bitset format passes validation
|
||||
await client.send_json(
|
||||
{
|
||||
ID: 23,
|
||||
TYPE: "ozw/set_config_parameter",
|
||||
NODE_ID: 39,
|
||||
PARAMETER: 10000,
|
||||
VALUE: {ATTR_POSITION: 1, ATTR_VALUE: True},
|
||||
}
|
||||
)
|
||||
msg = await client.receive_json()
|
||||
result = msg["error"]
|
||||
assert result["code"] == ERR_NOT_FOUND
|
||||
|
||||
|
||||
async def test_refresh_node(hass, generic_data, sent_messages, hass_ws_client):
|
||||
"""Test the ozw refresh node api."""
|
||||
|
||||
Reference in new issue
Block a user