diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index 15d3a68d4a4..a4fca557242 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -326,6 +326,7 @@ def async_register_api(hass: HomeAssistant) -> None: websocket_api.async_register_command(hass, websocket_network_status) websocket_api.async_register_command(hass, websocket_node_status) websocket_api.async_register_command(hass, websocket_node_metadata) + websocket_api.async_register_command(hass, websocket_node_comments) websocket_api.async_register_command(hass, websocket_add_node) websocket_api.async_register_command(hass, websocket_grant_security_classes) websocket_api.async_register_command(hass, websocket_validate_dsk_and_enter_pin) @@ -503,7 +504,6 @@ async def websocket_node_metadata( "wakeup": node.device_config.metadata.wakeup, "reset": node.device_config.metadata.reset, "device_database_url": node.device_database_url, - "comments": node.device_config.metadata.comments, } connection.send_result( msg[ID], @@ -511,6 +511,27 @@ async def websocket_node_metadata( ) +@websocket_api.websocket_command( + { + vol.Required(TYPE): "zwave_js/node_comments", + vol.Required(DEVICE_ID): str, + } +) +@websocket_api.async_response +@async_get_node +async def websocket_node_comments( + hass: HomeAssistant, + connection: ActiveConnection, + msg: dict, + node: Node, +) -> None: + """Get the comments of a Z-Wave JS node.""" + connection.send_result( + msg[ID], + {"comments": node.device_config.metadata.comments}, + ) + + @websocket_api.require_admin @websocket_api.websocket_command( { diff --git a/tests/components/zwave_js/test_api.py b/tests/components/zwave_js/test_api.py index 58c26cd5797..2309e7b02bf 100644 --- a/tests/components/zwave_js/test_api.py +++ b/tests/components/zwave_js/test_api.py @@ -261,7 +261,6 @@ async def test_node_metadata(hass, wallmote_central_scene, integration, hass_ws_ result["device_database_url"] == "https://devices.zwave-js.io/?jumpTo=0x0086:0x0002:0x0082:0.0" ) - assert result["comments"] == [{"level": "info", "text": "test"}] # Test getting non-existent node fails await ws_client.send_json( @@ -292,6 +291,26 @@ async def test_node_metadata(hass, wallmote_central_scene, integration, hass_ws_ assert msg["error"]["code"] == ERR_NOT_LOADED +async def test_node_comments(hass, wallmote_central_scene, integration, hass_ws_client): + """Test the node comments websocket command.""" + ws_client = await hass_ws_client(hass) + + dev_reg = dr.async_get(hass) + device = dev_reg.async_get_device({(DOMAIN, "3245146787-35")}) + assert device + + await ws_client.send_json( + { + ID: 3, + TYPE: "zwave_js/node_comments", + DEVICE_ID: device.id, + } + ) + msg = await ws_client.receive_json() + result = msg["result"] + assert result["comments"] == [{"level": "info", "text": "test"}] + + async def test_add_node( hass, nortek_thermostat_added_event, integration, client, hass_ws_client ):