mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add zwave_js WS API command to call node.refresh_info (#48564)
This commit is contained in:
parent
ceeb060c05
commit
ebb369e008
@ -60,6 +60,7 @@ def async_register_api(hass: HomeAssistant) -> None:
|
|||||||
websocket_api.async_register_command(hass, websocket_stop_inclusion)
|
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_remove_node)
|
||||||
websocket_api.async_register_command(hass, websocket_stop_exclusion)
|
websocket_api.async_register_command(hass, websocket_stop_exclusion)
|
||||||
|
websocket_api.async_register_command(hass, websocket_refresh_node_info)
|
||||||
websocket_api.async_register_command(hass, websocket_update_log_config)
|
websocket_api.async_register_command(hass, websocket_update_log_config)
|
||||||
websocket_api.async_register_command(hass, websocket_get_log_config)
|
websocket_api.async_register_command(hass, websocket_get_log_config)
|
||||||
websocket_api.async_register_command(hass, websocket_get_config_parameters)
|
websocket_api.async_register_command(hass, websocket_get_config_parameters)
|
||||||
@ -301,6 +302,32 @@ async def websocket_remove_node(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@websocket_api.require_admin # type: ignore
|
||||||
|
@websocket_api.async_response
|
||||||
|
@websocket_api.websocket_command(
|
||||||
|
{
|
||||||
|
vol.Required(TYPE): "zwave_js/refresh_node_info",
|
||||||
|
vol.Required(ENTRY_ID): str,
|
||||||
|
vol.Required(NODE_ID): int,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
async def websocket_refresh_node_info(
|
||||||
|
hass: HomeAssistant, connection: ActiveConnection, msg: dict
|
||||||
|
) -> None:
|
||||||
|
"""Re-interview a node."""
|
||||||
|
entry_id = msg[ENTRY_ID]
|
||||||
|
node_id = msg[NODE_ID]
|
||||||
|
client = hass.data[DOMAIN][entry_id][DATA_CLIENT]
|
||||||
|
node = client.driver.controller.nodes.get(node_id)
|
||||||
|
|
||||||
|
if node is None:
|
||||||
|
connection.send_error(msg[ID], ERR_NOT_FOUND, f"Node {node_id} not found")
|
||||||
|
return
|
||||||
|
|
||||||
|
await node.async_refresh_info()
|
||||||
|
connection.send_result(msg[ID])
|
||||||
|
|
||||||
|
|
||||||
@websocket_api.require_admin # type:ignore
|
@websocket_api.require_admin # type:ignore
|
||||||
@websocket_api.async_response
|
@websocket_api.async_response
|
||||||
@websocket_api.websocket_command(
|
@websocket_api.websocket_command(
|
||||||
|
@ -222,6 +222,45 @@ async def test_remove_node(
|
|||||||
assert device is None
|
assert device is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_refresh_node_info(
|
||||||
|
hass, client, integration, hass_ws_client, multisensor_6
|
||||||
|
):
|
||||||
|
"""Test that the refresh_node_info WS API call works."""
|
||||||
|
entry = integration
|
||||||
|
ws_client = await hass_ws_client(hass)
|
||||||
|
|
||||||
|
client.async_send_command_no_wait.return_value = None
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
ID: 1,
|
||||||
|
TYPE: "zwave_js/refresh_node_info",
|
||||||
|
ENTRY_ID: entry.entry_id,
|
||||||
|
NODE_ID: 52,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = await ws_client.receive_json()
|
||||||
|
assert msg["success"]
|
||||||
|
|
||||||
|
assert len(client.async_send_command_no_wait.call_args_list) == 1
|
||||||
|
args = client.async_send_command_no_wait.call_args[0][0]
|
||||||
|
assert args["command"] == "node.refresh_info"
|
||||||
|
assert args["nodeId"] == 52
|
||||||
|
|
||||||
|
client.async_send_command_no_wait.reset_mock()
|
||||||
|
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
ID: 2,
|
||||||
|
TYPE: "zwave_js/refresh_node_info",
|
||||||
|
ENTRY_ID: entry.entry_id,
|
||||||
|
NODE_ID: 999,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = await ws_client.receive_json()
|
||||||
|
assert not msg["success"]
|
||||||
|
assert msg["error"]["code"] == "not_found"
|
||||||
|
|
||||||
|
|
||||||
async def test_set_config_parameter(
|
async def test_set_config_parameter(
|
||||||
hass, client, hass_ws_client, multisensor_6, integration
|
hass, client, hass_ws_client, multisensor_6, integration
|
||||||
):
|
):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user