Skip to content

Commit

Permalink
Add support for zwave-js 12.0 and schema 32 (#757)
Browse files Browse the repository at this point in the history
* Add support for zwave-js 12.0 and schema 32

* additional changes

* fix mypy

* lint

* Add coverage

* Incorporate #758 and add coverage

* Switch order

* Add message to FailedCommand

* Fix exception logic

* fix tests

* black

* fix typehint

* Change exception slightly

* fix test

* Remove defunct function
  • Loading branch information
raman325 authored Sep 26, 2023
1 parent b13b12e commit 903d339
Show file tree
Hide file tree
Showing 20 changed files with 334 additions and 135 deletions.
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def version_data_fixture():
"serverVersion": "test_server_version",
"homeId": "test_home_id",
"minSchemaVersion": 0,
"maxSchemaVersion": 31,
"maxSchemaVersion": 32,
}


Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/basic_dump.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/controller_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
],
"sucNodeId": 1,
"supportsTimers": false,
"isHealNetworkActive": false,
"isRebuildingRoutes": false,
"inclusionState": 0
},
"nodes": []
Expand Down
154 changes: 101 additions & 53 deletions test/model/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,32 @@
from zwave_js_server.model import association as association_pkg
from zwave_js_server.model import controller as controller_pkg
from zwave_js_server.model.controller.firmware import ControllerFirmwareUpdateStatus
from zwave_js_server.model.controller.rebuild_routes import (
RebuildRoutesOptions,
RebuildRoutesStatus,
)
from zwave_js_server.model.controller.statistics import ControllerStatistics
from zwave_js_server.model.node import Node
from zwave_js_server.model.node.firmware import NodeFirmwareUpdateFileInfo
from zwave_js_server.model.node.firmware import NodeFirmwareUpdateInfo

from .. import load_fixture

FIRMWARE_UPDATE_INFO = {
"version": "1.0.0",
"changelog": "changelog",
"channel": "stable",
"files": [{"target": 0, "url": "http://example.com", "integrity": "test"}],
"downgrade": True,
"normalizedVersion": "1.0.0",
"device": {
"manufacturerId": 1,
"productType": 2,
"productId": 3,
"firmwareVersion": "0.4.4",
"rfRegion": 1,
},
}


def test_from_state():
"""Test from_state method."""
Expand Down Expand Up @@ -130,7 +150,7 @@ def test_from_state():
]
assert ctrl.suc_node_id == 1
assert ctrl.supports_timers is False
assert ctrl.is_heal_network_active is False
assert ctrl.is_rebuilding_routes is False
assert ctrl.inclusion_state == InclusionState.IDLE
stats = ctrl.statistics
assert (
Expand Down Expand Up @@ -979,66 +999,93 @@ async def test_replace_failed_node_errors(controller, multisensor_6):
)


async def test_heal_node(controller, multisensor_6, uuid4, mock_command):
"""Test heal node."""
async def test_rebuild_node_routes(controller, multisensor_6, uuid4, mock_command):
"""Test rebuild node routes."""
ack_commands = mock_command(
{"command": "controller.heal_node"},
{"command": "controller.rebuild_node_routes"},
{"success": True},
)

assert await controller.async_heal_node(multisensor_6)
assert await controller.async_rebuild_node_routes(multisensor_6)

assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "controller.heal_node",
"command": "controller.rebuild_node_routes",
"messageId": uuid4,
"nodeId": multisensor_6.node_id,
}


async def test_begin_healing_network(controller, uuid4, mock_command):
"""Test begin healing network."""
async def test_begin_rebuilding_routes(controller, uuid4, mock_command):
"""Test begin rebuilding routes."""
ack_commands = mock_command(
{"command": "controller.begin_healing_network"},
{"command": "controller.begin_rebuilding_routes"},
{"success": True},
)

assert await controller.async_begin_healing_network()
assert await controller.async_begin_rebuilding_routes()

assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "controller.begin_healing_network",
"command": "controller.begin_rebuilding_routes",
"messageId": uuid4,
}

options_include_sleeping = RebuildRoutesOptions(True)
assert await controller.async_begin_rebuilding_routes(options_include_sleeping)

assert len(ack_commands) == 2
assert ack_commands[1] == {
"command": "controller.begin_rebuilding_routes",
"options": {"includeSleeping": True},
"messageId": uuid4,
}

assert await controller.async_begin_rebuilding_routes(RebuildRoutesOptions())

assert len(ack_commands) == 3
assert ack_commands[2] == {
"command": "controller.begin_rebuilding_routes",
"options": {},
"messageId": uuid4,
}

assert (
RebuildRoutesOptions.from_dict({"includeSleeping": True})
== options_include_sleeping
)


async def test_stop_healing_network(controller, uuid4, mock_command):
"""Test stop healing network."""
async def test_stop_rebuilding_routes(client, multisensor_6, uuid4, mock_command):
"""Test stop rebuilding routes."""
controller = client.driver.controller
ack_commands = mock_command(
{"command": "controller.stop_healing_network"},
{"command": "controller.stop_rebuilding_routes"},
{"success": True},
)

event = Event(
"heal network progress",
"rebuild routes progress",
{
"source": "controller",
"event": "heal network progress",
"event": "rebuild routes progress",
"progress": {52: "pending"},
},
)
controller.receive_event(event)

assert controller.heal_network_progress == {52: "pending"}
assert await controller.async_stop_healing_network()
assert controller.rebuild_routes_progress == {
multisensor_6: RebuildRoutesStatus.PENDING
}
assert await controller.async_stop_rebuilding_routes()

assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "controller.stop_healing_network",
"command": "controller.stop_rebuilding_routes",
"messageId": uuid4,
}
# Verify that controller.heal_network_progress is cleared
assert controller.heal_network_progress is None
# Verify that controller.rebuild_routes_progress is cleared
assert controller.rebuild_routes_progress is None


async def test_is_failed_node(controller, multisensor_6, uuid4, mock_command):
Expand Down Expand Up @@ -1339,32 +1386,39 @@ async def test_get_node_neighbors(controller, multisensor_6, uuid4, mock_command
}


async def test_heal_network_active(client, controller):
"""Test that is_heal_network_active changes on events."""
assert controller.is_heal_network_active is False
assert controller.heal_network_progress is None
async def test_rebuild_routes_active(client, multisensor_6):
"""Test that is_rebuilding_routes changes on events."""
controller = client.driver.controller
assert controller.is_rebuilding_routes is False
assert controller.rebuild_routes_progress is None
event = Event(
"heal network progress",
"rebuild routes progress",
{
"source": "controller",
"event": "heal network progress",
"event": "rebuild routes progress",
"progress": {52: "pending"},
},
)
controller.receive_event(event)
assert controller.heal_network_progress == {52: "pending"}
assert controller.is_heal_network_active
assert controller.rebuild_routes_progress == {
multisensor_6: RebuildRoutesStatus.PENDING
}
assert controller.last_rebuild_routes_result is None
assert controller.is_rebuilding_routes
event = Event(
"heal network done",
"rebuild routes done",
{
"source": "controller",
"event": "heal network done",
"event": "rebuild routes done",
"result": {52: "failed"},
},
)
controller.receive_event(event)
assert controller.heal_network_progress is None
assert controller.is_heal_network_active is False
assert controller.rebuild_routes_progress is None
assert controller.last_rebuild_routes_result == {
multisensor_6: RebuildRoutesStatus.FAILED
}
assert controller.is_rebuilding_routes is False


async def test_statistics_updated(controller):
Expand Down Expand Up @@ -1789,31 +1843,28 @@ async def test_get_available_firmware_updates(multisensor_6, uuid4, mock_command
"""Test get available firmware updates."""
ack_commands = mock_command(
{"command": "controller.get_available_firmware_updates"},
{
"updates": [
{
"version": "1.0.0",
"changelog": "changelog",
"files": [
{"target": 0, "url": "http://example.com", "integrity": "test"}
],
}
]
},
{"updates": [FIRMWARE_UPDATE_INFO]},
)
updates = await multisensor_6.client.driver.controller.async_get_available_firmware_updates(
multisensor_6, "test"
)

assert len(updates) == 1
update = updates[0]
assert update.version == "1.0.0"
assert update.changelog == "changelog"
assert update.channel == "stable"
assert len(update.files) == 1
file = update.files[0]
assert file.target == 0
assert file.url == "http://example.com"
assert file.integrity == "test"
assert update.downgrade
assert update.normalized_version == "1.0.0"
assert update.device.manufacturer_id == 1
assert update.device.product_type == 2
assert update.device.product_id == 3
assert update.device.firmware_version == "0.4.4"
assert update.device.rf_region == RFRegion.USA

assert len(ack_commands) == 1
assert ack_commands[0] == {
Expand All @@ -1832,12 +1883,7 @@ async def test_begin_ota_firmware_update(multisensor_6, uuid4, mock_command):
{"result": {"status": 255, "success": True, "reInterview": False}},
)
result = await multisensor_6.client.driver.controller.async_firmware_update_ota(
multisensor_6,
[
NodeFirmwareUpdateFileInfo(
target=0, url="http://example.com", integrity="test"
)
],
multisensor_6, NodeFirmwareUpdateInfo.from_dict(FIRMWARE_UPDATE_INFO)
)
assert result.status == 255
assert result.success
Expand All @@ -1847,7 +1893,7 @@ async def test_begin_ota_firmware_update(multisensor_6, uuid4, mock_command):
assert ack_commands[0] == {
"command": "controller.firmware_update_ota",
"nodeId": multisensor_6.node_id,
"updates": [{"target": 0, "url": "http://example.com", "integrity": "test"}],
"updateInfo": FIRMWARE_UPDATE_INFO,
"messageId": uuid4,
}

Expand Down Expand Up @@ -1993,6 +2039,8 @@ async def test_node_added(controller, multisensor_6_state):

async def test_node_removed(client, multisensor_6, multisensor_6_state):
"""Test node removed event."""
assert 52 in client.driver.controller.nodes
assert client.driver.controller.nodes[52] == multisensor_6
event = Event(
"node removed",
{
Expand Down
13 changes: 0 additions & 13 deletions test/model/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,6 @@ async def test_set_preferred_scales(driver, uuid4, mock_command):
}


async def test_enable_error_reporting(driver, uuid4, mock_command):
"""Test driver.enable_error_reporting command."""
ack_commands = mock_command({"command": "driver.enable_error_reporting"}, {})

assert not await driver.async_enable_error_reporting()

assert len(ack_commands) == 1
assert ack_commands[0] == {
"command": "driver.enable_error_reporting",
"messageId": uuid4,
}


async def test_hard_reset(driver, uuid4, mock_command):
"""Test driver hard reset command."""
ack_commands = mock_command({"command": "driver.hard_reset"}, {})
Expand Down
Loading

0 comments on commit 903d339

Please sign in to comment.