From b5d29b307d0f98eb17ba93fd283b360f329deaa8 Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Fri, 12 Feb 2021 13:31:07 -0500 Subject: [PATCH 01/10] Add get_configuration_values websocket command to zwave_js --- homeassistant/components/zwave_js/api.py | 35 ++++++++++++++++++++++++ tests/components/zwave_js/test_api.py | 18 ++++++++++++ 2 files changed, 53 insertions(+) diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index bed2166a4da5cd..dd7c33d5de5e67 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -31,6 +31,7 @@ def async_register_api(hass: HomeAssistant) -> None: websocket_api.async_register_command(hass, websocket_stop_inclusion) websocket_api.async_register_command(hass, websocket_remove_node) websocket_api.async_register_command(hass, websocket_stop_exclusion) + websocket_api.async_register_command(hass, websocket_get_configuration_values) hass.http.register_view(DumpView) # type: ignore @@ -263,6 +264,40 @@ def node_removed(event: dict) -> None: ) +@websocket_api.require_admin +@websocket_api.websocket_command( + { + vol.Required(TYPE): "zwave_js/get_configuration_values", + vol.Required(ENTRY_ID): str, + vol.Required(NODE_ID): int, + } +) +@callback +def websocket_get_configuration_values( + hass: HomeAssistant, connection: ActiveConnection, msg: dict +) -> None: + """Get a list of configuration values for a Z-Wave node.""" + entry_id = msg[ENTRY_ID] + node_id = msg[NODE_ID] + client = hass.data[DOMAIN][entry_id][DATA_CLIENT] + node = client.driver.controller.nodes[node_id] + values = node.get_configuration_values() + result = {} + for value in values: + result[value] = { + "property": values[value].data["property"], + "property_name": values[value].data["propertyName"], + "metadata": values[value].data["metadata"], + "value": values[value].data.get( + "value" + ), # Some config properties don't return a value + } + connection.send_result( + msg[ID], + result, + ) + + class DumpView(HomeAssistantView): """View to dump the state of the Z-Wave JS server.""" diff --git a/tests/components/zwave_js/test_api.py b/tests/components/zwave_js/test_api.py index a36743421c95d3..795dbb4af0e279 100644 --- a/tests/components/zwave_js/test_api.py +++ b/tests/components/zwave_js/test_api.py @@ -41,6 +41,24 @@ async def test_websocket_api(hass, integration, multisensor_6, hass_ws_client): assert not result["is_secure"] assert result["status"] == 1 + # Test getting configuration values + await ws_client.send_json( + { + ID: 4, + TYPE: "zwave_js/get_configuration_values", + ENTRY_ID: entry.entry_id, + NODE_ID: node.node_id, + } + ) + msg = await ws_client.receive_json() + result = msg["result"] + + assert len(result) == 44 + key = "52-112-00-2-00" + assert result[key]["property"] == 2 + assert result[key]["property_name"] == "Stay Awake in Battery Mode" + assert result[key]["metadata"]["type"] == "number" + async def test_add_node( hass, integration, client, hass_ws_client, nortek_thermostat_added_event From e6726b34ce862b7c5f77b50978579ffbbf94d2cf Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Fri, 12 Feb 2021 16:13:18 -0500 Subject: [PATCH 02/10] Tweak return value --- homeassistant/components/zwave_js/api.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index dd7c33d5de5e67..442157f095a4ab 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -284,13 +284,22 @@ def websocket_get_configuration_values( values = node.get_configuration_values() result = {} for value in values: + metadata = values[value].metadata result[value] = { - "property": values[value].data["property"], - "property_name": values[value].data["propertyName"], - "metadata": values[value].data["metadata"], - "value": values[value].data.get( - "value" - ), # Some config properties don't return a value + "property": values[value].property_, + "property_name": values[value].property_name, + "property_key": values[value].property_key, + "type": values[value].type.value, + "metadata": { + "description": metadata.description, + "label": metadata.label, + "type": metadata.type, + "min": metadata.min, + "max": metadata.max, + "unit": metadata.unit, + "writeable": metadata.writeable, + }, + "value": values[value].value, } connection.send_result( msg[ID], From 20259ecd02fa36c2313cba7a8ed2c9b3a06f8b9a Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Sun, 14 Feb 2021 19:17:00 -0500 Subject: [PATCH 03/10] Review comments and cleanup returned values --- homeassistant/components/zwave_js/api.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index 442157f095a4ab..ec4256aa9a1142 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -283,13 +283,11 @@ def websocket_get_configuration_values( node = client.driver.controller.nodes[node_id] values = node.get_configuration_values() result = {} - for value in values: - metadata = values[value].metadata - result[value] = { - "property": values[value].property_, - "property_name": values[value].property_name, - "property_key": values[value].property_key, - "type": values[value].type.value, + for value_id, zwave_value in values.items(): + metadata = zwave_value.metadata + result[value_id] = { + "property": zwave_value.property_, + "configuration_value_type": zwave_value.configuration_value_type.value, "metadata": { "description": metadata.description, "label": metadata.label, @@ -299,7 +297,7 @@ def websocket_get_configuration_values( "unit": metadata.unit, "writeable": metadata.writeable, }, - "value": values[value].value, + "value": zwave_value.value, } connection.send_result( msg[ID], From 701aea305a109bfdb910fa8641feee6f0152c887 Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Mon, 15 Feb 2021 10:49:05 -0500 Subject: [PATCH 04/10] Update test --- tests/components/zwave_js/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/zwave_js/test_api.py b/tests/components/zwave_js/test_api.py index 795dbb4af0e279..9b121e494f1f89 100644 --- a/tests/components/zwave_js/test_api.py +++ b/tests/components/zwave_js/test_api.py @@ -56,8 +56,8 @@ async def test_websocket_api(hass, integration, multisensor_6, hass_ws_client): assert len(result) == 44 key = "52-112-00-2-00" assert result[key]["property"] == 2 - assert result[key]["property_name"] == "Stay Awake in Battery Mode" assert result[key]["metadata"]["type"] == "number" + assert result[key]["configuration_value_type"] == "enumerated" async def test_add_node( From 49102137606701dcd70c9f7a5a80f7a93621b797 Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Sun, 21 Feb 2021 14:05:47 -0500 Subject: [PATCH 05/10] Rename to get_config_parameters --- homeassistant/components/zwave_js/api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index ec4256aa9a1142..a3fa76c8458022 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -31,7 +31,7 @@ def async_register_api(hass: HomeAssistant) -> None: websocket_api.async_register_command(hass, websocket_stop_inclusion) websocket_api.async_register_command(hass, websocket_remove_node) websocket_api.async_register_command(hass, websocket_stop_exclusion) - websocket_api.async_register_command(hass, websocket_get_configuration_values) + websocket_api.async_register_command(hass, websocket_get_config_parameters) hass.http.register_view(DumpView) # type: ignore @@ -267,16 +267,16 @@ def node_removed(event: dict) -> None: @websocket_api.require_admin @websocket_api.websocket_command( { - vol.Required(TYPE): "zwave_js/get_configuration_values", + vol.Required(TYPE): "zwave_js/get_config_parameters", vol.Required(ENTRY_ID): str, vol.Required(NODE_ID): int, } ) @callback -def websocket_get_configuration_values( +def websocket_get_config_parameters( hass: HomeAssistant, connection: ActiveConnection, msg: dict ) -> None: - """Get a list of configuration values for a Z-Wave node.""" + """Get a list of configuration parameterss for a Z-Wave node.""" entry_id = msg[ENTRY_ID] node_id = msg[NODE_ID] client = hass.data[DOMAIN][entry_id][DATA_CLIENT] From 979211f7b01daf3edff159af08dc75b6c214c32b Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Fri, 12 Feb 2021 13:31:07 -0500 Subject: [PATCH 06/10] Add get_configuration_values websocket command to zwave_js --- homeassistant/components/zwave_js/api.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index a3fa76c8458022..1c9f6e793dc5bb 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -31,7 +31,11 @@ def async_register_api(hass: HomeAssistant) -> None: websocket_api.async_register_command(hass, websocket_stop_inclusion) websocket_api.async_register_command(hass, websocket_remove_node) websocket_api.async_register_command(hass, websocket_stop_exclusion) +<<<<<<< HEAD websocket_api.async_register_command(hass, websocket_get_config_parameters) +======= + websocket_api.async_register_command(hass, websocket_get_configuration_values) +>>>>>>> 5bb3567170... Add get_configuration_values websocket command to zwave_js hass.http.register_view(DumpView) # type: ignore From 08d36b253a403a6930012136839d323f9e26b4b4 Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Sun, 21 Feb 2021 14:05:47 -0500 Subject: [PATCH 07/10] Rename to get_config_parameters --- homeassistant/components/zwave_js/api.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index 1c9f6e793dc5bb..a3fa76c8458022 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -31,11 +31,7 @@ def async_register_api(hass: HomeAssistant) -> None: websocket_api.async_register_command(hass, websocket_stop_inclusion) websocket_api.async_register_command(hass, websocket_remove_node) websocket_api.async_register_command(hass, websocket_stop_exclusion) -<<<<<<< HEAD websocket_api.async_register_command(hass, websocket_get_config_parameters) -======= - websocket_api.async_register_command(hass, websocket_get_configuration_values) ->>>>>>> 5bb3567170... Add get_configuration_values websocket command to zwave_js hass.http.register_view(DumpView) # type: ignore From b195496bba13b5c4aafc9d59f079761cfd9bb66f Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Sun, 21 Feb 2021 23:12:47 -0500 Subject: [PATCH 08/10] fix test --- tests/components/zwave_js/test_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/components/zwave_js/test_api.py b/tests/components/zwave_js/test_api.py index 9b121e494f1f89..6af4f0cab6cc82 100644 --- a/tests/components/zwave_js/test_api.py +++ b/tests/components/zwave_js/test_api.py @@ -41,11 +41,11 @@ async def test_websocket_api(hass, integration, multisensor_6, hass_ws_client): assert not result["is_secure"] assert result["status"] == 1 - # Test getting configuration values + # Test getting configuration parameter values await ws_client.send_json( { ID: 4, - TYPE: "zwave_js/get_configuration_values", + TYPE: "zwave_js/get_config_parameters", ENTRY_ID: entry.entry_id, NODE_ID: node.node_id, } From d7ae66b2b4ab547573eef271668a8c0c8d88a985 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 22 Feb 2021 00:38:39 -0500 Subject: [PATCH 09/10] fix tests #2 --- tests/components/zwave_js/test_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/components/zwave_js/test_api.py b/tests/components/zwave_js/test_api.py index 6af4f0cab6cc82..7689f7140f4c56 100644 --- a/tests/components/zwave_js/test_api.py +++ b/tests/components/zwave_js/test_api.py @@ -53,8 +53,8 @@ async def test_websocket_api(hass, integration, multisensor_6, hass_ws_client): msg = await ws_client.receive_json() result = msg["result"] - assert len(result) == 44 - key = "52-112-00-2-00" + assert len(result) == 61 + key = "52-112-0-2-00-00" assert result[key]["property"] == 2 assert result[key]["metadata"]["type"] == "number" assert result[key]["configuration_value_type"] == "enumerated" From a3e761943354fcb5ac2c8494dda0dc71b613f989 Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Mon, 22 Feb 2021 10:17:49 -0500 Subject: [PATCH 10/10] Add readable to metadata --- homeassistant/components/zwave_js/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index a3fa76c8458022..fb9282b4763efe 100644 --- a/homeassistant/components/zwave_js/api.py +++ b/homeassistant/components/zwave_js/api.py @@ -296,6 +296,7 @@ def websocket_get_config_parameters( "max": metadata.max, "unit": metadata.unit, "writeable": metadata.writeable, + "readable": metadata.readable, }, "value": zwave_value.value, }