Skip to content

Commit

Permalink
Update remove_node to include new optional parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 committed Nov 17, 2021
1 parent 1297f3a commit fb0259f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
24 changes: 14 additions & 10 deletions homeassistant/components/zwave_js/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,6 @@

DSK = "dsk"

PLANNED_PROVISIONING_ENTRY_SCHEMA = vol.Schema(
{
vol.Required(DSK): str,
vol.Required(SECURITY_CLASSES): vol.All(cv.ensure_list, [int]),
},
# Provisioning entries can have extra keys for SmartStart
extra=vol.ALLOW_EXTRA,
)

VERSION = "version"
GENERIC_DEVICE_CLASS = "generic_device_class"
SPECIFIC_DEVICE_CLASS = "specific_device_class"
Expand All @@ -145,6 +136,18 @@
UUID = "uuid"
SUPPORTED_PROTOCOLS = "supported_protocols"

UNPROVISION = "unprovision"

# Helper schemas
PLANNED_PROVISIONING_ENTRY_SCHEMA = vol.Schema(
{
vol.Required(DSK): str,
vol.Required(SECURITY_CLASSES): vol.All(cv.ensure_list, [int]),
},
# Provisioning entries can have extra keys for SmartStart
extra=vol.ALLOW_EXTRA,
)

QR_PROVISIONING_INFORMATION_SCHEMA = vol.Schema(
{
vol.Required(VERSION): int,
Expand Down Expand Up @@ -914,6 +917,7 @@ async def websocket_stop_exclusion(
{
vol.Required(TYPE): "zwave_js/remove_node",
vol.Required(ENTRY_ID): str,
vol.Optional(UNPROVISION): bool,
}
)
@websocket_api.async_response
Expand Down Expand Up @@ -962,7 +966,7 @@ def node_removed(event: dict) -> None:
controller.on("node removed", node_removed),
]

result = await controller.async_begin_exclusion()
result = await controller.async_begin_exclusion(msg.get(UNPROVISION))
connection.send_result(
msg[ID],
result,
Expand Down
43 changes: 42 additions & 1 deletion tests/components/zwave_js/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
SECURITY_CLASSES,
SPECIFIC_DEVICE_CLASS,
TYPE,
UNPROVISION,
VALUE,
VERSION,
)
Expand Down Expand Up @@ -439,6 +440,7 @@ async def test_add_node(

client.async_send_command.return_value = {"success": True}

# Test inclusion with no provisioning input
await ws_client.send_json(
{
ID: 1,
Expand Down Expand Up @@ -563,6 +565,7 @@ async def test_add_node(
client.async_send_command.reset_mock()
client.async_send_command.return_value = {"success": True}

# Test S2 planned provisioning entry
await ws_client.send_json(
{
ID: 2,
Expand Down Expand Up @@ -593,6 +596,7 @@ async def test_add_node(
client.async_send_command.reset_mock()
client.async_send_command.return_value = {"success": True}

# Test S2 QR provisioning information
await ws_client.send_json(
{
ID: 3,
Expand Down Expand Up @@ -643,6 +647,7 @@ async def test_add_node(
client.async_send_command.reset_mock()
client.async_send_command.return_value = {"success": True}

# Test S2 QR code string
await ws_client.send_json(
{
ID: 4,
Expand Down Expand Up @@ -807,6 +812,7 @@ async def test_provision_smart_start_node(hass, integration, client, hass_ws_cli

client.async_send_command.return_value = {"success": True}

# Test provisioning entry
await ws_client.send_json(
{
ID: 2,
Expand All @@ -833,6 +839,7 @@ async def test_provision_smart_start_node(hass, integration, client, hass_ws_cli
client.async_send_command.reset_mock()
client.async_send_command.return_value = {"success": True}

# Test QR provisioning information
await ws_client.send_json(
{
ID: 3,
Expand Down Expand Up @@ -879,6 +886,7 @@ async def test_provision_smart_start_node(hass, integration, client, hass_ws_cli
client.async_send_command.reset_mock()
client.async_send_command.return_value = {"success": True}

# Test QR code string
await ws_client.send_json(
{
ID: 4,
Expand Down Expand Up @@ -956,6 +964,7 @@ async def test_unprovision_smart_start_node(hass, integration, client, hass_ws_c

client.async_send_command.return_value = {}

# Test node ID as input
await ws_client.send_json(
{
ID: 1,
Expand All @@ -977,6 +986,7 @@ async def test_unprovision_smart_start_node(hass, integration, client, hass_ws_c
client.async_send_command.reset_mock()
client.async_send_command.return_value = {}

# Test DSK as input
await ws_client.send_json(
{
ID: 2,
Expand Down Expand Up @@ -1281,12 +1291,17 @@ async def test_remove_node(
client.async_send_command.return_value = {"success": True}

await ws_client.send_json(
{ID: 3, TYPE: "zwave_js/remove_node", ENTRY_ID: entry.entry_id}
{ID: 1, TYPE: "zwave_js/remove_node", ENTRY_ID: entry.entry_id}
)

msg = await ws_client.receive_json()
assert msg["success"]

assert len(client.async_send_command.call_args_list) == 1
assert client.async_send_command.call_args[0][0] == {
"command": "controller.begin_exclusion",
}

event = Event(
type="exclusion started",
data={
Expand Down Expand Up @@ -1319,6 +1334,28 @@ async def test_remove_node(
)
assert device is None

# Test unprovision parameter
client.async_send_command.reset_mock()
client.async_send_command.return_value = {"success": True}

await ws_client.send_json(
{
ID: 2,
TYPE: "zwave_js/remove_node",
ENTRY_ID: entry.entry_id,
UNPROVISION: True,
}
)

msg = await ws_client.receive_json()
assert msg["success"]

assert len(client.async_send_command.call_args_list) == 1
assert client.async_send_command.call_args[0][0] == {
"command": "controller.begin_exclusion",
"unprovision": True,
}

# Test FailedZWaveCommand is caught
with patch(
"zwave_js_server.model.controller.Controller.async_begin_exclusion",
Expand Down Expand Up @@ -1374,6 +1411,7 @@ async def test_replace_failed_node(

client.async_send_command.return_value = {"success": True}

# Test replace failed node with no provisioning information
# Order of events we receive for a successful replacement is `inclusion started`,
# `inclusion stopped`, `node removed`, `node added`, then interview stages.
await ws_client.send_json(
Expand Down Expand Up @@ -1527,6 +1565,7 @@ async def test_replace_failed_node(
client.async_send_command.reset_mock()
client.async_send_command.return_value = {"success": True}

# Test S2 planned provisioning entry
await ws_client.send_json(
{
ID: 2,
Expand Down Expand Up @@ -1559,6 +1598,7 @@ async def test_replace_failed_node(
client.async_send_command.reset_mock()
client.async_send_command.return_value = {"success": True}

# Test S2 QR provisioning information
await ws_client.send_json(
{
ID: 3,
Expand Down Expand Up @@ -1611,6 +1651,7 @@ async def test_replace_failed_node(
client.async_send_command.reset_mock()
client.async_send_command.return_value = {"success": True}

# Test S2 QR code string
await ws_client.send_json(
{
ID: 4,
Expand Down

0 comments on commit fb0259f

Please sign in to comment.