Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions homeassistant/components/zwave_js/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_remove_node)
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_get_log_config)
websocket_api.async_register_command(hass, websocket_get_config_parameters)
Expand Down Expand Up @@ -301,6 +302,32 @@ def node_removed(event: dict) -> None:
)


@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()
Comment thread
raman325 marked this conversation as resolved.
connection.send_result(msg[ID])


@websocket_api.require_admin # type:ignore
@websocket_api.async_response
@websocket_api.websocket_command(
Expand Down
39 changes: 39 additions & 0 deletions tests/components/zwave_js/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,45 @@ async def test_remove_node(
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(
hass, client, hass_ws_client, multisensor_6, integration
):
Expand Down