Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_config_parameters websocket command to zwave_js #46463

Merged
merged 10 commits into from
Feb 22, 2021
43 changes: 43 additions & 0 deletions homeassistant/components/zwave_js/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -263,6 +264,48 @@ def node_removed(event: dict) -> None:
)


@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,
cgarwood marked this conversation as resolved.
Show resolved Hide resolved
"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."""

Expand Down
18 changes: 18 additions & 0 deletions tests/components/zwave_js/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down