Add new zwave_js WS command to parse DSK from QR code (#87237)
* Add new zwave_js WS command to parse DSK from QR code * remove minimum character check since it is not needed in this case
This commit is contained in:
parent
f7bfdfefde
commit
5683d21931
2 changed files with 99 additions and 4 deletions
|
@ -1431,9 +1431,72 @@ async def test_parse_qr_code_string(
|
|||
assert msg["error"]["code"] == ERR_NOT_LOADED
|
||||
|
||||
|
||||
async def test_supports_feature(
|
||||
hass: HomeAssistant, integration, client, hass_ws_client: WebSocketGenerator
|
||||
) -> None:
|
||||
async def test_try_parse_dsk_from_qr_code_string(
|
||||
hass, integration, client, hass_ws_client
|
||||
):
|
||||
"""Test try_parse_dsk_from_qr_code_string websocket command."""
|
||||
entry = integration
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
client.async_send_command.return_value = {"dsk": "a"}
|
||||
|
||||
await ws_client.send_json(
|
||||
{
|
||||
ID: 1,
|
||||
TYPE: "zwave_js/try_parse_dsk_from_qr_code_string",
|
||||
ENTRY_ID: entry.entry_id,
|
||||
QR_CODE_STRING: "90testtesttesttesttesttesttesttesttesttesttesttesttest",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await ws_client.receive_json()
|
||||
assert msg["success"]
|
||||
assert msg["result"] == "a"
|
||||
|
||||
assert len(client.async_send_command.call_args_list) == 1
|
||||
assert client.async_send_command.call_args[0][0] == {
|
||||
"command": "utils.try_parse_dsk_from_qr_code_string",
|
||||
"qr": "90testtesttesttesttesttesttesttesttesttesttesttesttest",
|
||||
}
|
||||
|
||||
# Test FailedZWaveCommand is caught
|
||||
with patch(
|
||||
"homeassistant.components.zwave_js.api.async_try_parse_dsk_from_qr_code_string",
|
||||
side_effect=FailedZWaveCommand("failed_command", 1, "error message"),
|
||||
):
|
||||
await ws_client.send_json(
|
||||
{
|
||||
ID: 6,
|
||||
TYPE: "zwave_js/try_parse_dsk_from_qr_code_string",
|
||||
ENTRY_ID: entry.entry_id,
|
||||
QR_CODE_STRING: "90testtesttesttesttesttesttesttesttesttesttesttesttest",
|
||||
}
|
||||
)
|
||||
msg = await ws_client.receive_json()
|
||||
|
||||
assert not msg["success"]
|
||||
assert msg["error"]["code"] == "zwave_error"
|
||||
assert msg["error"]["message"] == "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: 7,
|
||||
TYPE: "zwave_js/try_parse_dsk_from_qr_code_string",
|
||||
ENTRY_ID: entry.entry_id,
|
||||
QR_CODE_STRING: "90testtesttesttesttesttesttesttesttesttesttesttesttest",
|
||||
}
|
||||
)
|
||||
msg = await ws_client.receive_json()
|
||||
|
||||
assert not msg["success"]
|
||||
assert msg["error"]["code"] == ERR_NOT_LOADED
|
||||
|
||||
|
||||
async def test_supports_feature(hass, integration, client, hass_ws_client):
|
||||
"""Test supports_feature websocket command."""
|
||||
entry = integration
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue