Skip to content

Commit 7f5460b

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 0eefa43 commit 7f5460b

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
@@ -210,3 +210,21 @@ class CommissioningParameters:
210210
setup_pin_code: int
211211
setup_manual_code: str
212212
setup_qr_code: str
213+
214+
215+
@dataclass
216+
class MatterSoftwareVersion:
217+
"""Representation of a Matter software version. Return by the check_node_update command.
218+
219+
This holds Matter software version information similar to what is available from the CSA DCL.
220+
https://on.dcl.csa-iot.org/#/Query/ModelVersion.
221+
"""
222+
223+
vid: int
224+
pid: int
225+
software_version: int
226+
software_version_string: str
227+
firmware_information: str | None
228+
min_applicable_software_version: int
229+
max_applicable_software_version: int
230+
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
@@ -887,7 +891,7 @@ async def import_test_node(self, dump: str) -> None:
887891
self.server.signal_event(EventType.NODE_ADDED, node)
888892

889893
@api_command(APICommand.CHECK_NODE_UPDATE)
890-
async def check_node_update(self, node_id: int) -> dict | None:
894+
async def check_node_update(self, node_id: int) -> MatterSoftwareVersion | None:
891895
"""
892896
Check if there is an update for a particular node.
893897
@@ -896,12 +900,36 @@ async def check_node_update(self, node_id: int) -> dict | None:
896900
information of the latest update available.
897901
"""
898902

899-
return await self._check_node_update(node_id)
903+
update = await self._check_node_update(node_id)
904+
if update is None:
905+
return None
906+
907+
if not all(
908+
key in update
909+
for key in [
910+
"vid",
911+
"pid",
912+
"softwareVersion",
913+
"softwareVersionString",
914+
"minApplicableSoftwareVersion",
915+
"maxApplicableSoftwareVersion",
916+
]
917+
):
918+
raise UpdateCheckError("Invalid update data")
919+
920+
return MatterSoftwareVersion(
921+
vid=update["vid"],
922+
pid=update["pid"],
923+
software_version=update["softwareVersion"],
924+
software_version_string=update["softwareVersionString"],
925+
firmware_information=update.get("firmwareInformation", None),
926+
min_applicable_software_version=update["minApplicableSoftwareVersion"],
927+
max_applicable_software_version=update["maxApplicableSoftwareVersion"],
928+
release_notes_url=update.get("releaseNotesUrl", None),
929+
)
900930

901931
@api_command(APICommand.UPDATE_NODE)
902-
async def update_node(
903-
self, node_id: int, software_version: int | str
904-
) -> dict | None:
932+
async def update_node(self, node_id: int, software_version: int | str) -> None:
905933
"""
906934
Update a node to a new software version.
907935
@@ -954,8 +982,6 @@ async def update_node(
954982
)
955983
self._nodes_in_ota.remove(node_id)
956984

957-
return update
958-
959985
async def _check_node_update(
960986
self,
961987
node_id: int,

0 commit comments

Comments
 (0)