Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rebuildRoutesProgress to state dump for controller #833

Merged
merged 3 commits into from
Dec 11, 2023
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
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def version_data_fixture():
"serverVersion": "test_server_version",
"homeId": "test_home_id",
"minSchemaVersion": 0,
"maxSchemaVersion": 33,
"maxSchemaVersion": 34,
}


Expand Down
7 changes: 5 additions & 2 deletions test/model/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,23 @@ def test_from_state():
== 0
)
assert ctrl.rf_region is None
assert ctrl.rebuild_routes_progress is None


def test_controller_mods():
def test_controller_mods(client):
"""Test modifications to controller method."""
state = json.loads(load_fixture("basic_dump.txt").split("\n")[0])["result"]["state"]
state["controller"].pop("ownNodeId")
state["controller"]["rfRegion"] = 0
state["controller"]["status"] = 0
state["controller"]["rebuildRoutesProgress"] = {1: "pending"}

ctrl = controller_pkg.Controller(None, state)
ctrl = controller_pkg.Controller(client, state)
assert ctrl.own_node_id is None
assert ctrl.own_node is None
assert ctrl.rf_region == RFRegion.EUROPE
assert ctrl.status == ControllerStatus.READY
assert ctrl.rebuild_routes_progress == {ctrl.nodes[1]: RebuildRoutesStatus.PENDING}


def test_controller_status():
Expand Down
2 changes: 1 addition & 1 deletion test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ async def test_additional_user_agent_components(client_session, url):
{
"command": "initialize",
"messageId": "initialize",
"schemaVersion": 33,
"schemaVersion": 34,
"additionalUserAgentComponents": {
"zwave-js-server-python": __version__,
"foo": "bar",
Expand Down
2 changes: 1 addition & 1 deletion test/test_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def test_dump_additional_user_agent_components(
{
"command": "initialize",
"messageId": "initialize",
"schemaVersion": 33,
"schemaVersion": 34,
"additionalUserAgentComponents": {
"zwave-js-server-python": __version__,
"foo": "bar",
Expand Down
2 changes: 1 addition & 1 deletion test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_dump_state(
assert captured.out == (
"{'type': 'version', 'driverVersion': 'test_driver_version', "
"'serverVersion': 'test_server_version', 'homeId': 'test_home_id', "
"'minSchemaVersion': 0, 'maxSchemaVersion': 33}\n"
"'minSchemaVersion': 0, 'maxSchemaVersion': 34}\n"
"{'type': 'result', 'success': True, 'result': {}, 'messageId': 'initialize'}\n"
"test_result\n"
)
Expand Down
4 changes: 2 additions & 2 deletions zwave_js_server/const/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
__version__ = "0.54.0"

# minimal server schema version we can handle
MIN_SERVER_SCHEMA_VERSION = 33
MIN_SERVER_SCHEMA_VERSION = 34
# max server schema version we can handle (and our code is compatible with)
MAX_SERVER_SCHEMA_VERSION = 33
MAX_SERVER_SCHEMA_VERSION = 34

VALUE_UNKNOWN = "unknown"

Expand Down
27 changes: 19 additions & 8 deletions zwave_js_server/model/controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ def __eq__(self, other: object) -> bool:
return False
return self.home_id == other.home_id

def _generate_rebuild_routes_status(
self, data: dict[str, str]
) -> dict[Node, RebuildRoutesStatus]:
"""Generate rebuild routes status."""
return {
self.nodes[int(node_id)]: RebuildRoutesStatus(status)
for node_id, status in data.items()
}

@property
def sdk_version(self) -> str | None:
"""Return sdk_version."""
Expand Down Expand Up @@ -240,6 +249,10 @@ def update(self, data: ControllerDataType) -> None:
self._statistics = ControllerStatistics(
self.data.get("statistics", DEFAULT_CONTROLLER_STATISTICS)
)
if "rebuildRoutesProgress" in self.data:
self._rebuild_routes_progress = self._generate_rebuild_routes_status(
self.data["rebuildRoutesProgress"]
)

async def async_begin_inclusion(
self,
Expand Down Expand Up @@ -903,18 +916,16 @@ def handle_node_removed(self, event: Event) -> None:

def handle_rebuild_routes_progress(self, event: Event) -> None:
"""Process a rebuild routes progress event."""
self._rebuild_routes_progress = {
self.nodes[int(node_id)]: RebuildRoutesStatus(status)
for node_id, status in event.data["progress"].items()
}
self._rebuild_routes_progress = self._generate_rebuild_routes_status(
event.data["progress"]
)
self.data["isRebuildingRoutes"] = True

def handle_rebuild_routes_done(self, event: Event) -> None:
"""Process a rebuild routes done event."""
self._last_rebuild_routes_result = {
self.nodes[int(node_id)]: RebuildRoutesStatus(status)
for node_id, status in event.data["result"].items()
}
self._last_rebuild_routes_result = self._generate_rebuild_routes_status(
event.data["result"]
)
self._rebuild_routes_progress = None
self.data["isRebuildingRoutes"] = False

Expand Down
3 changes: 2 additions & 1 deletion zwave_js_server/model/controller/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ControllerDataType(TypedDict, total=False):
isPrimary: bool
isSUC: bool
nodeType: int
isUsingHomeIdFromOtherNetwork: bool # TODO: The following items are missing in the docs.
isUsingHomeIdFromOtherNetwork: bool
isSISPresent: bool
wasRealPrimary: bool
firmwareVersion: str
Expand All @@ -31,3 +31,4 @@ class ControllerDataType(TypedDict, total=False):
inclusionState: int
rfRegion: int
status: int
rebuildRoutesProgress: dict[str, str]