Fix zwave_js/node_state WS API command (#55979)
* Fix zwave_js/node_state WS API command * Add negative assertion check to avoid regression * Update tests/components/zwave_js/test_api.py Co-authored-by: jan iversen <jancasacondor@gmail.com> * use constant Co-authored-by: jan iversen <jancasacondor@gmail.com>
This commit is contained in:
parent
88dbc6373f
commit
113288cb1f
3 changed files with 40 additions and 3 deletions
|
@ -3,7 +3,7 @@ import json
|
|||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from zwave_js_server.const import InclusionStrategy, LogLevel
|
||||
from zwave_js_server.const import CommandClass, InclusionStrategy, LogLevel
|
||||
from zwave_js_server.event import Event
|
||||
from zwave_js_server.exceptions import (
|
||||
FailedCommand,
|
||||
|
@ -12,6 +12,7 @@ from zwave_js_server.exceptions import (
|
|||
NotFoundError,
|
||||
SetValueFailed,
|
||||
)
|
||||
from zwave_js_server.model.value import _get_value_id_from_dict, get_value_id
|
||||
|
||||
from homeassistant.components.websocket_api.const import ERR_NOT_FOUND
|
||||
from homeassistant.components.zwave_js.api import (
|
||||
|
@ -39,6 +40,8 @@ from homeassistant.components.zwave_js.const import (
|
|||
)
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .common import PROPERTY_ULTRAVIOLET
|
||||
|
||||
|
||||
async def test_network_status(hass, integration, hass_ws_client):
|
||||
"""Test the network status websocket command."""
|
||||
|
@ -127,6 +130,28 @@ async def test_node_state(hass, multisensor_6, integration, hass_ws_client):
|
|||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
node = multisensor_6
|
||||
|
||||
# Update a value and ensure it is reflected in the node state
|
||||
value_id = get_value_id(node, CommandClass.SENSOR_MULTILEVEL, PROPERTY_ULTRAVIOLET)
|
||||
event = Event(
|
||||
type="value updated",
|
||||
data={
|
||||
"source": "node",
|
||||
"event": "value updated",
|
||||
"nodeId": node.node_id,
|
||||
"args": {
|
||||
"commandClassName": "Multilevel Sensor",
|
||||
"commandClass": 49,
|
||||
"endpoint": 0,
|
||||
"property": PROPERTY_ULTRAVIOLET,
|
||||
"newValue": 1,
|
||||
"prevValue": 0,
|
||||
"propertyName": PROPERTY_ULTRAVIOLET,
|
||||
},
|
||||
},
|
||||
)
|
||||
node.receive_event(event)
|
||||
|
||||
await ws_client.send_json(
|
||||
{
|
||||
ID: 3,
|
||||
|
@ -136,7 +161,17 @@ async def test_node_state(hass, multisensor_6, integration, hass_ws_client):
|
|||
}
|
||||
)
|
||||
msg = await ws_client.receive_json()
|
||||
assert msg["result"] == node.data
|
||||
|
||||
# Assert that the data returned doesn't match the stale node state data
|
||||
assert msg["result"] != node.data
|
||||
|
||||
# Replace data for the value we updated and assert the new node data is the same
|
||||
# as what's returned
|
||||
updated_node_data = node.data.copy()
|
||||
for n, value in enumerate(updated_node_data["values"]):
|
||||
if _get_value_id_from_dict(node, value) == value_id:
|
||||
updated_node_data["values"][n] = node.values[value_id].data.copy()
|
||||
assert msg["result"] == updated_node_data
|
||||
|
||||
# Test getting non-existent node fails
|
||||
await ws_client.send_json(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue