diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index 6cd0ea4fe44..549f1b1b950 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -307,7 +307,7 @@ async def websocket_node_state( """Get the state data of a Z-Wave JS node.""" connection.send_result( msg[ID], - node.data, + {**node.data, "values": [value.data for value in node.values.values()]}, ) diff --git a/tests/components/zwave_js/common.py b/tests/components/zwave_js/common.py index 2590149c462..e8e3151134c 100644 --- a/tests/components/zwave_js/common.py +++ b/tests/components/zwave_js/common.py @@ -33,3 +33,5 @@ ID_LOCK_CONFIG_PARAMETER_SENSOR = ( ZEN_31_ENTITY = "light.kitchen_under_cabinet_lights" METER_ENERGY_SENSOR = "sensor.smart_switch_6_electric_consumed_kwh" METER_VOLTAGE_SENSOR = "sensor.smart_switch_6_electric_consumed_v" + +PROPERTY_ULTRAVIOLET = "Ultraviolet" diff --git a/tests/components/zwave_js/test_api.py b/tests/components/zwave_js/test_api.py index b3bb924413d..29c0ce4bba4 100644 --- a/tests/components/zwave_js/test_api.py +++ b/tests/components/zwave_js/test_api.py @@ -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(