Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node.async_set_raw_config_parameter_value command #780

Merged
merged 16 commits into from
Oct 24, 2023
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def version_data_fixture():
"serverVersion": "test_server_version",
"homeId": "test_home_id",
"minSchemaVersion": 0,
"maxSchemaVersion": 32,
"maxSchemaVersion": 33,
}


Expand Down
133 changes: 132 additions & 1 deletion test/model/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
from zwave_js_server.const import (
INTERVIEW_FAILED,
CommandClass,
CommandStatus,
NodeStatus,
PowerLevel,
ProtocolDataRate,
ProtocolVersion,
RFRegion,
SecurityClass,
SupervisionStatus,
Weekday,
)
from zwave_js_server.const.command_class.entry_control import (
Expand Down Expand Up @@ -44,7 +46,12 @@
RouteHealthCheckResultDataType,
)
from zwave_js_server.model.node.statistics import NodeStatistics
from zwave_js_server.model.value import ConfigurationValue, get_value_id_str
from zwave_js_server.model.value import (
ConfigurationValue,
ConfigurationValueFormat,
SetConfigParameterResult,
get_value_id_str,
)

from .. import load_fixture

Expand Down Expand Up @@ -2502,3 +2509,127 @@ async def test_is_secure_none(client, multisensor_6_state):
node_state.pop("isSecure")
node = node_pkg.Node(client, node_state)
assert node.is_secure is None


async def test_set_raw_config_parameter_value(
multisensor_6: node_pkg.Node, uuid4, mock_command
):
"""Test set raw config parameter value."""
node = multisensor_6

ack_commands = mock_command(
{"command": "endpoint.set_raw_config_parameter_value", "nodeId": node.node_id},
{},
)

assert await node.async_set_raw_config_parameter_value(
1, 101, 1
) == SetConfigParameterResult(CommandStatus.QUEUED)

assert len(ack_commands) == 1

assert ack_commands[0] == {
"command": "endpoint.set_raw_config_parameter_value",
"nodeId": node.node_id,
"endpoint": 0,
"options": {
"parameter": 101,
"bitMask": 1,
"value": 1,
},
"messageId": uuid4,
}

assert await node.async_set_raw_config_parameter_value(
"Disable", "Stay Awake in Battery Mode"
) == SetConfigParameterResult(CommandStatus.QUEUED)

assert len(ack_commands) == 2

assert ack_commands[1] == {
"command": "endpoint.set_raw_config_parameter_value",
"nodeId": node.node_id,
"endpoint": 0,
"options": {
"parameter": 2,
"value": 0,
},
"messageId": uuid4,
}

# wake up node
event = Event(
"wake up", {"source": "node", "event": "wake up", "nodeId": node.node_id}
)
node.receive_event(event)

assert await node.async_set_raw_config_parameter_value(
1, 2, value_size=1, value_format=ConfigurationValueFormat.SIGNED_INTEGER
) == SetConfigParameterResult(CommandStatus.ACCEPTED)

assert len(ack_commands) == 3

assert ack_commands[2] == {
"command": "endpoint.set_raw_config_parameter_value",
"nodeId": node.node_id,
"endpoint": 0,
"options": {
"parameter": 2,
"valueSize": 1,
"valueFormat": 0,
"value": 1,
},
"messageId": uuid4,
}

# Test failures
with pytest.raises(NotFoundError):
await node.async_set_raw_config_parameter_value(
"fake", "Stay Awake in Battery Mode"
)

with pytest.raises(NotFoundError):
await node.async_set_raw_config_parameter_value(1, 1000)

with pytest.raises(ValueError):
await node.async_set_raw_config_parameter_value(1, 101, 1, 1)

with pytest.raises(ValueError):
await node.async_set_raw_config_parameter_value(
1, 101, 1, value_format=ConfigurationValueFormat.SIGNED_INTEGER
)

with pytest.raises(ValueError):
await node.async_set_raw_config_parameter_value(
1, 101, 1, 1, ConfigurationValueFormat.SIGNED_INTEGER
)


async def test_supervision_result(inovelli_switch: node_pkg.Node, uuid4, mock_command):
"""Test Supervision Result."""
node = inovelli_switch

mock_command(
{"command": "endpoint.set_raw_config_parameter_value", "nodeId": node.node_id},
{"result": {"status": 1, "remainingDuration": "default"}},
)

result = await node.async_set_raw_config_parameter_value(1, 1)
assert result.result.status is SupervisionStatus.WORKING
duration = result.result.remaining_duration
assert duration.unit == "default"


async def test_supervision_result_invalid(
inovelli_switch: node_pkg.Node, uuid4, mock_command
):
"""Test invalid Supervision Result."""
node = inovelli_switch

mock_command(
{"command": "endpoint.set_raw_config_parameter_value", "nodeId": node.node_id},
{"result": {"status": 1}},
)

with pytest.raises(ValueError):
await node.async_set_raw_config_parameter_value(1, 1)
2 changes: 1 addition & 1 deletion test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ async def test_additional_user_agent_components(client_session, url):
{
"command": "initialize",
"messageId": "initialize",
"schemaVersion": 32,
"schemaVersion": 33,
"additionalUserAgentComponents": {
"zwave-js-server-python": __version__,
"foo": "bar",
Expand Down
2 changes: 1 addition & 1 deletion test/test_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def test_dump_additional_user_agent_components(
{
"command": "initialize",
"messageId": "initialize",
"schemaVersion": 32,
"schemaVersion": 33,
"additionalUserAgentComponents": {
"zwave-js-server-python": __version__,
"foo": "bar",
Expand Down
2 changes: 1 addition & 1 deletion test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_dump_state(
assert captured.out == (
"{'type': 'version', 'driverVersion': 'test_driver_version', "
"'serverVersion': 'test_server_version', 'homeId': 'test_home_id', "
"'minSchemaVersion': 0, 'maxSchemaVersion': 32}\n"
"'minSchemaVersion': 0, 'maxSchemaVersion': 33}\n"
"{'type': 'result', 'success': True, 'result': {}, 'messageId': 'initialize'}\n"
"test_result\n"
)
Expand Down
20 changes: 10 additions & 10 deletions test/util/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def test_configuration_parameter_values(
node_2, 190, 8, 255, endpoint=endpoint
)
assert isinstance(zwave_value, ConfigurationValue)
assert cmd_status == CommandStatus.ACCEPTED
assert cmd_status.status == CommandStatus.ACCEPTED

value = node_2.values[f"31-112-{endpoint}-8-255"]
assert len(ack_commands_2) == 1
Expand All @@ -95,7 +95,7 @@ async def test_configuration_parameter_values(
node_2, "Blue", 8, 255, endpoint=endpoint
)
assert isinstance(zwave_value, ConfigurationValue)
assert cmd_status == CommandStatus.ACCEPTED
assert cmd_status.status == CommandStatus.ACCEPTED

value = node_2.values[f"31-112-{endpoint}-8-255"]
assert len(ack_commands_2) == 2
Expand Down Expand Up @@ -131,7 +131,7 @@ async def test_configuration_parameter_values(
node, "2.0\u00b0 F", "Temperature Reporting Threshold", endpoint=endpoint
)
assert isinstance(zwave_value, ConfigurationValue)
assert cmd_status == CommandStatus.ACCEPTED
assert cmd_status.status == CommandStatus.ACCEPTED

value = node.values[f"13-112-{endpoint}-1"]
assert len(ack_commands) == 3
Expand Down Expand Up @@ -169,7 +169,7 @@ async def test_bulk_set_partial_config_parameters(
cmd_status = await async_bulk_set_partial_config_parameters(
node, 101, 241, endpoint=endpoint
)
assert cmd_status == CommandStatus.QUEUED
assert cmd_status.status == CommandStatus.QUEUED
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_value",
Expand All @@ -186,7 +186,7 @@ async def test_bulk_set_partial_config_parameters(
cmd_status = await async_bulk_set_partial_config_parameters(
node, 101, {128: 1, 64: 1, 32: 1, 16: 1, 1: 1}, endpoint=endpoint
)
assert cmd_status == CommandStatus.QUEUED
assert cmd_status.status == CommandStatus.QUEUED
assert len(ack_commands) == 2
assert ack_commands[1] == {
"command": "node.set_value",
Expand All @@ -204,7 +204,7 @@ async def test_bulk_set_partial_config_parameters(
cmd_status = await async_bulk_set_partial_config_parameters(
node, 101, {64: 1, 32: 1, 16: 1, 1: 1}, endpoint=endpoint
)
assert cmd_status == CommandStatus.QUEUED
assert cmd_status.status == CommandStatus.QUEUED
assert len(ack_commands) == 3
assert ack_commands[2] == {
"command": "node.set_value",
Expand All @@ -230,7 +230,7 @@ async def test_bulk_set_partial_config_parameters(
},
endpoint=endpoint,
)
assert cmd_status == CommandStatus.QUEUED
assert cmd_status.status == CommandStatus.QUEUED
assert len(ack_commands) == 4
assert ack_commands[3] == {
"command": "node.set_value",
Expand Down Expand Up @@ -303,7 +303,7 @@ async def test_bulk_set_with_full_and_partial_parameters(
node, 8, 34867929, endpoint=endpoint
)

assert cmd_status == CommandStatus.ACCEPTED
assert cmd_status.status == CommandStatus.ACCEPTED
assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "node.set_value",
Expand Down Expand Up @@ -370,13 +370,13 @@ async def test_returned_values(endpoint, client, multisensor_6_state, mock_comma
cmd_status = await async_bulk_set_partial_config_parameters(
node, 101, {64: 1, 32: 1, 16: 1, 1: 1}, endpoint=endpoint
)
assert cmd_status == CommandStatus.ACCEPTED
assert cmd_status.status == CommandStatus.ACCEPTED

zwave_value, cmd_status = await async_set_config_parameter(
node, 1, 101, 64, endpoint=endpoint
)
assert isinstance(zwave_value, ConfigurationValue)
assert cmd_status == CommandStatus.ACCEPTED
assert cmd_status.status == CommandStatus.ACCEPTED


async def test_dump_node_state(inovelli_switch, inovelli_switch_state):
Expand Down
14 changes: 12 additions & 2 deletions zwave_js_server/const/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
__version__ = metadata.version(PACKAGE_NAME)

# minimal server schema version we can handle
MIN_SERVER_SCHEMA_VERSION = 32
MIN_SERVER_SCHEMA_VERSION = 33
# max server schema version we can handle (and our code is compatible with)
MAX_SERVER_SCHEMA_VERSION = 32
MAX_SERVER_SCHEMA_VERSION = 33

VALUE_UNKNOWN = "unknown"

Expand Down Expand Up @@ -495,3 +495,13 @@ class ControllerStatus(IntEnum):
UNRESPONSIVE = 1
# The controller is unable to transmit
JAMMED = 2


class SupervisionStatus(IntEnum):
"""Enum for all known supervision statuses."""

# https://github.com/zwave-js/node-zwave-js/blob/cc_api_options/packages/core/src/consts/Transmission.ts#L304
NO_SUPPORT = 0
WORKING = 1
FAIL = 2
SUCCESS = 255
Loading