Skip to content

Commit 3b121a8

Browse files
committed
Add MatterSoftwareVersion model for check_node_update
Use a new model MatterSoftwareVersion to store the software version information typically fetched from DCL for the Matter nodes.
1 parent 672f112 commit 3b121a8

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

matter_server/client/client.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
EventType,
3030
MatterNodeData,
3131
MatterNodeEvent,
32+
MatterSoftwareVersion,
3233
MessageType,
3334
NodePingResult,
3435
ResultMessageBase,
@@ -509,7 +510,7 @@ async def interview_node(self, node_id: int) -> None:
509510
"""Interview a node."""
510511
await self.send_command(APICommand.INTERVIEW_NODE, node_id=node_id)
511512

512-
async def check_node_update(self, node_id: int) -> dict[str, Any]:
513+
async def check_node_update(self, node_id: int) -> MatterSoftwareVersion | None:
513514
"""Check Node for updates.
514515
515516
Return a dict with the available update information. Most notable
@@ -518,10 +519,11 @@ async def check_node_update(self, node_id: int) -> dict[str, Any]:
518519
519520
The "softwareVersionString" is a human friendly version string.
520521
"""
521-
node_update = await self.send_command(
522-
APICommand.CHECK_NODE_UPDATE, node_id=node_id
523-
)
524-
return cast(dict[str, Any], node_update)
522+
data = await self.send_command(APICommand.CHECK_NODE_UPDATE, node_id=node_id)
523+
if data is None:
524+
return None
525+
526+
return dataclass_from_dict(MatterSoftwareVersion, data)
525527

526528
async def update_node(
527529
self,

matter_server/common/models.py

+18
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,21 @@ class CommissioningParameters:
211211
setup_pin_code: int
212212
setup_manual_code: str
213213
setup_qr_code: str
214+
215+
216+
@dataclass
217+
class MatterSoftwareVersion:
218+
"""Representation of a Matter software version. Return by the check_node_update command.
219+
220+
This holds Matter software version information similar to what is available from the CSA DCL.
221+
https://on.dcl.csa-iot.org/#/Query/ModelVersion.
222+
"""
223+
224+
vid: int
225+
pid: int
226+
software_version: int
227+
software_version_string: str
228+
firmware_information: str | None
229+
min_applicable_software_version: int
230+
max_applicable_software_version: int
231+
release_notes_url: str | None

matter_server/server/device_controller.py

+34-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828

2929
from matter_server.common.const import VERBOSE_LOG_LEVEL
3030
from matter_server.common.custom_clusters import check_polled_attributes
31-
from matter_server.common.models import CommissionableNodeData, CommissioningParameters
31+
from matter_server.common.models import (
32+
CommissionableNodeData,
33+
CommissioningParameters,
34+
MatterSoftwareVersion,
35+
)
3236
from matter_server.server.helpers.attributes import parse_attributes_from_read_result
3337
from matter_server.server.helpers.utils import ping_ip
3438
from matter_server.server.ota import check_for_update
@@ -897,7 +901,7 @@ async def import_test_node(self, dump: str) -> None:
897901
self.server.signal_event(EventType.NODE_ADDED, node)
898902

899903
@api_command(APICommand.CHECK_NODE_UPDATE)
900-
async def check_node_update(self, node_id: int) -> dict | None:
904+
async def check_node_update(self, node_id: int) -> MatterSoftwareVersion | None:
901905
"""
902906
Check if there is an update for a particular node.
903907
@@ -906,12 +910,36 @@ async def check_node_update(self, node_id: int) -> dict | None:
906910
information of the latest update available.
907911
"""
908912

909-
return await self._check_node_update(node_id)
913+
update = await self._check_node_update(node_id)
914+
if update is None:
915+
return None
916+
917+
if not all(
918+
key in update
919+
for key in [
920+
"vid",
921+
"pid",
922+
"softwareVersion",
923+
"softwareVersionString",
924+
"minApplicableSoftwareVersion",
925+
"maxApplicableSoftwareVersion",
926+
]
927+
):
928+
raise UpdateCheckError("Invalid update data")
929+
930+
return MatterSoftwareVersion(
931+
vid=update["vid"],
932+
pid=update["pid"],
933+
software_version=update["softwareVersion"],
934+
software_version_string=update["softwareVersionString"],
935+
firmware_information=update.get("firmwareInformation", None),
936+
min_applicable_software_version=update["minApplicableSoftwareVersion"],
937+
max_applicable_software_version=update["maxApplicableSoftwareVersion"],
938+
release_notes_url=update.get("releaseNotesUrl", None),
939+
)
910940

911941
@api_command(APICommand.UPDATE_NODE)
912-
async def update_node(
913-
self, node_id: int, software_version: int | str
914-
) -> dict | None:
942+
async def update_node(self, node_id: int, software_version: int | str) -> None:
915943
"""
916944
Update a node to a new software version.
917945
@@ -964,8 +992,6 @@ async def update_node(
964992
)
965993
self._nodes_in_ota.remove(node_id)
966994

967-
return update
968-
969995
async def _check_node_update(
970996
self,
971997
node_id: int,

0 commit comments

Comments
 (0)