mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 10:47:51 +00:00
Add Z-Wave WS command to hard reset controller (#101449)
This commit is contained in:
parent
d46dca8950
commit
70a0cd579d
@ -447,6 +447,7 @@ def async_register_api(hass: HomeAssistant) -> None:
|
|||||||
hass, websocket_subscribe_controller_statistics
|
hass, websocket_subscribe_controller_statistics
|
||||||
)
|
)
|
||||||
websocket_api.async_register_command(hass, websocket_subscribe_node_statistics)
|
websocket_api.async_register_command(hass, websocket_subscribe_node_statistics)
|
||||||
|
websocket_api.async_register_command(hass, websocket_hard_reset_controller)
|
||||||
hass.http.register_view(FirmwareUploadView(dr.async_get(hass)))
|
hass.http.register_view(FirmwareUploadView(dr.async_get(hass)))
|
||||||
|
|
||||||
|
|
||||||
@ -2441,3 +2442,26 @@ async def websocket_subscribe_node_statistics(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@websocket_api.require_admin
|
||||||
|
@websocket_api.websocket_command(
|
||||||
|
{
|
||||||
|
vol.Required(TYPE): "zwave_js/hard_reset_controller",
|
||||||
|
vol.Required(ENTRY_ID): str,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@websocket_api.async_response
|
||||||
|
@async_handle_failed_command
|
||||||
|
@async_get_entry
|
||||||
|
async def websocket_hard_reset_controller(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
connection: ActiveConnection,
|
||||||
|
msg: dict[str, Any],
|
||||||
|
entry: ConfigEntry,
|
||||||
|
client: Client,
|
||||||
|
driver: Driver,
|
||||||
|
) -> None:
|
||||||
|
"""Hard reset controller."""
|
||||||
|
await driver.async_hard_reset()
|
||||||
|
connection.send_result(msg[ID])
|
||||||
|
@ -4650,3 +4650,72 @@ async def test_subscribe_node_statistics(
|
|||||||
|
|
||||||
assert not msg["success"]
|
assert not msg["success"]
|
||||||
assert msg["error"]["code"] == ERR_NOT_LOADED
|
assert msg["error"]["code"] == ERR_NOT_LOADED
|
||||||
|
|
||||||
|
|
||||||
|
async def test_hard_reset_controller(
|
||||||
|
hass: HomeAssistant, client, integration, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
|
"""Test that the hard_reset_controller WS API call works."""
|
||||||
|
entry = integration
|
||||||
|
ws_client = await hass_ws_client(hass)
|
||||||
|
|
||||||
|
client.async_send_command.return_value = {}
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
ID: 1,
|
||||||
|
TYPE: "zwave_js/hard_reset_controller",
|
||||||
|
ENTRY_ID: entry.entry_id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = await ws_client.receive_json()
|
||||||
|
assert msg["result"] is None
|
||||||
|
assert msg["success"]
|
||||||
|
|
||||||
|
assert len(client.async_send_command.call_args_list) == 1
|
||||||
|
assert client.async_send_command.call_args[0][0] == {"command": "driver.hard_reset"}
|
||||||
|
|
||||||
|
# Test FailedZWaveCommand is caught
|
||||||
|
with patch(
|
||||||
|
"zwave_js_server.model.driver.Driver.async_hard_reset",
|
||||||
|
side_effect=FailedZWaveCommand("failed_command", 1, "error message"),
|
||||||
|
):
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
ID: 2,
|
||||||
|
TYPE: "zwave_js/hard_reset_controller",
|
||||||
|
ENTRY_ID: entry.entry_id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = await ws_client.receive_json()
|
||||||
|
|
||||||
|
assert not msg["success"]
|
||||||
|
assert msg["error"]["code"] == "zwave_error"
|
||||||
|
assert msg["error"]["message"] == "zwave_error: Z-Wave error 1 - error message"
|
||||||
|
|
||||||
|
# Test sending command with not loaded entry fails
|
||||||
|
await hass.config_entries.async_unload(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
ID: 3,
|
||||||
|
TYPE: "zwave_js/hard_reset_controller",
|
||||||
|
ENTRY_ID: entry.entry_id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = await ws_client.receive_json()
|
||||||
|
|
||||||
|
assert not msg["success"]
|
||||||
|
assert msg["error"]["code"] == ERR_NOT_LOADED
|
||||||
|
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
ID: 4,
|
||||||
|
TYPE: "zwave_js/hard_reset_controller",
|
||||||
|
ENTRY_ID: "INVALID",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
msg = await ws_client.receive_json()
|
||||||
|
|
||||||
|
assert not msg["success"]
|
||||||
|
assert msg["error"]["code"] == ERR_NOT_FOUND
|
||||||
|
Loading…
x
Reference in New Issue
Block a user