Add get_config_parameters websocket command to zwave_js (#46463)
* Add get_configuration_values websocket command to zwave_js * Tweak return value * Review comments and cleanup returned values * Update test * Rename to get_config_parameters * Add get_configuration_values websocket command to zwave_js * Rename to get_config_parameters * fix test * fix tests #2 * Add readable to metadata Co-authored-by: Raman Gupta <7243222+raman325@users.noreply.github.com>pull/46931/head
parent
be33336d96
commit
04e07d8b2c
|
@ -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."""
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue