From a1b81b2de4172bc8affa74a87e35a8b20a74eac4 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 17 Feb 2022 05:38:20 -0500 Subject: [PATCH] Add inclusion state to zwave_js/network_status WS API cmd (#65398) --- homeassistant/components/zwave_js/api.py | 2 ++ .../zwave_js/fixtures/controller_state.json | 3 ++- tests/components/zwave_js/test_api.py | 13 ++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index f347a5187ea..4e68cc2e2dd 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -367,6 +367,7 @@ async def websocket_network_status( ) -> None: """Get the status of the Z-Wave JS network.""" controller = client.driver.controller + await controller.async_get_state() data = { "client": { "ws_server_url": client.ws_server_url, @@ -393,6 +394,7 @@ async def websocket_network_status( "suc_node_id": controller.suc_node_id, "supports_timers": controller.supports_timers, "is_heal_network_active": controller.is_heal_network_active, + "inclusion_state": controller.inclusion_state, "nodes": list(client.driver.controller.nodes), }, } diff --git a/tests/components/zwave_js/fixtures/controller_state.json b/tests/components/zwave_js/fixtures/controller_state.json index d4bf58a53ce..ac0cedcffef 100644 --- a/tests/components/zwave_js/fixtures/controller_state.json +++ b/tests/components/zwave_js/fixtures/controller_state.json @@ -92,7 +92,8 @@ ], "sucNodeId": 1, "supportsTimers": false, - "isHealNetworkActive": false + "isHealNetworkActive": false, + "inclusionState": 0 }, "nodes": [ ] diff --git a/tests/components/zwave_js/test_api.py b/tests/components/zwave_js/test_api.py index 3f29c3a2e67..8362854a5f6 100644 --- a/tests/components/zwave_js/test_api.py +++ b/tests/components/zwave_js/test_api.py @@ -6,6 +6,7 @@ from unittest.mock import patch import pytest from zwave_js_server.const import ( + InclusionState, InclusionStrategy, LogLevel, Protocols, @@ -77,14 +78,16 @@ async def test_network_status(hass, integration, hass_ws_client): entry = integration ws_client = await hass_ws_client(hass) - await ws_client.send_json( - {ID: 2, TYPE: "zwave_js/network_status", ENTRY_ID: entry.entry_id} - ) - msg = await ws_client.receive_json() - result = msg["result"] + with patch("zwave_js_server.model.controller.Controller.async_get_state"): + await ws_client.send_json( + {ID: 2, TYPE: "zwave_js/network_status", ENTRY_ID: entry.entry_id} + ) + msg = await ws_client.receive_json() + result = msg["result"] assert result["client"]["ws_server_url"] == "ws://test:3000/zjs" assert result["client"]["server_version"] == "1.0.0" + assert result["controller"]["inclusion_state"] == InclusionState.IDLE # Test sending command with not loaded entry fails await hass.config_entries.async_unload(entry.entry_id)