Skip to content

Commit

Permalink
Add MatterSoftwareVersion model for check_node_update
Browse files Browse the repository at this point in the history
Use a new model MatterSoftwareVersion to store the software version
information typically fetched from DCL for the Matter nodes.
  • Loading branch information
agners committed Jun 24, 2024
1 parent b48e669 commit 0bf4bc5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
12 changes: 7 additions & 5 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
EventType,
MatterNodeData,
MatterNodeEvent,
MatterSoftwareVersion,
MessageType,
NodePingResult,
ResultMessageBase,
Expand Down Expand Up @@ -509,7 +510,7 @@ async def interview_node(self, node_id: int) -> None:
"""Interview a node."""
await self.send_command(APICommand.INTERVIEW_NODE, node_id=node_id)

async def check_node_update(self, node_id: int) -> dict[str, Any]:
async def check_node_update(self, node_id: int) -> MatterSoftwareVersion | None:
"""Check Node for updates.
Return a dict with the available update information. Most notable
Expand All @@ -518,10 +519,11 @@ async def check_node_update(self, node_id: int) -> dict[str, Any]:
The "softwareVersionString" is a human friendly version string.
"""
node_update = await self.send_command(
APICommand.CHECK_NODE_UPDATE, node_id=node_id
)
return cast(dict[str, Any], node_update)
data = await self.send_command(APICommand.CHECK_NODE_UPDATE, node_id=node_id)
if data is None:
return None

return dataclass_from_dict(MatterSoftwareVersion, data)

async def update_node(
self,
Expand Down
18 changes: 18 additions & 0 deletions matter_server/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,21 @@ class CommissioningParameters:
setup_pin_code: int
setup_manual_code: str
setup_qr_code: str


@dataclass
class MatterSoftwareVersion:
"""Representation of a Matter software version. Return by the check_node_update command.
This holds Matter software version information similar to what is available from the CSA DCL.
https://on.dcl.csa-iot.org/#/Query/ModelVersion.
"""

vid: int
pid: int
software_version: int
software_version_string: str
firmware_information: str | None
min_applicable_software_version: int
max_applicable_software_version: int
release_notes_url: str | None
42 changes: 34 additions & 8 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@

from matter_server.common.const import VERBOSE_LOG_LEVEL
from matter_server.common.custom_clusters import check_polled_attributes
from matter_server.common.models import CommissionableNodeData, CommissioningParameters
from matter_server.common.models import (
CommissionableNodeData,
CommissioningParameters,
MatterSoftwareVersion,
)
from matter_server.server.helpers.attributes import parse_attributes_from_read_result
from matter_server.server.helpers.utils import ping_ip
from matter_server.server.ota import check_for_update
Expand Down Expand Up @@ -888,7 +892,7 @@ async def import_test_node(self, dump: str) -> None:
self.server.signal_event(EventType.NODE_ADDED, node)

@api_command(APICommand.CHECK_NODE_UPDATE)
async def check_node_update(self, node_id: int) -> dict | None:
async def check_node_update(self, node_id: int) -> MatterSoftwareVersion | None:
"""
Check if there is an update for a particular node.
Expand All @@ -897,12 +901,36 @@ async def check_node_update(self, node_id: int) -> dict | None:
information of the latest update available.
"""

return await self._check_node_update(node_id)
update = await self._check_node_update(node_id)
if update is None:
return None

if not all(
key in update
for key in [
"vid",
"pid",
"softwareVersion",
"softwareVersionString",
"minApplicableSoftwareVersion",
"maxApplicableSoftwareVersion",
]
):
raise UpdateCheckError("Invalid update data")

return MatterSoftwareVersion(
vid=update["vid"],
pid=update["pid"],
software_version=update["softwareVersion"],
software_version_string=update["softwareVersionString"],
firmware_information=update.get("firmwareInformation", None),
min_applicable_software_version=update["minApplicableSoftwareVersion"],
max_applicable_software_version=update["maxApplicableSoftwareVersion"],
release_notes_url=update.get("releaseNotesUrl", None),
)

@api_command(APICommand.UPDATE_NODE)
async def update_node(
self, node_id: int, software_version: int | str
) -> dict | None:
async def update_node(self, node_id: int, software_version: int | str) -> None:
"""
Update a node to a new software version.
Expand Down Expand Up @@ -955,8 +983,6 @@ async def update_node(
)
self._nodes_in_ota.remove(node_id)

return update

async def _check_node_update(
self,
node_id: int,
Expand Down

0 comments on commit 0bf4bc5

Please sign in to comment.