diff --git a/homeassistant/components/zwave_js/api.py b/homeassistant/components/zwave_js/api.py index bed2166a4da..fb9282b4763 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_config_parameters) hass.http.register_view(DumpView) # type: ignore @@ -263,6 +264,48 @@ async def websocket_remove_node( ) +@websocket_api.require_admin +@websocket_api.websocket_command( + { + vol.Required(TYPE): "zwave_js/get_config_parameters", + vol.Required(ENTRY_ID): str, + vol.Required(NODE_ID): int, + } +) +@callback +def websocket_get_config_parameters( + hass: HomeAssistant, connection: ActiveConnection, msg: dict +) -> None: + """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] + node = client.driver.controller.nodes[node_id] + values = node.get_configuration_values() + result = {} + 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, + "type": metadata.type, + "min": metadata.min, + "max": metadata.max, + "unit": metadata.unit, + "writeable": metadata.writeable, + "readable": metadata.readable, + }, + "value": zwave_value.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 a36743421c9..7689f7140f4 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 parameter values + await ws_client.send_json( + { + ID: 4, + TYPE: "zwave_js/get_config_parameters", + ENTRY_ID: entry.entry_id, + NODE_ID: node.node_id, + } + ) + msg = await ws_client.receive_json() + result = msg["result"] + + 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" + async def test_add_node( hass, integration, client, hass_ws_client, nortek_thermostat_added_event