Skip to content

Commit 0bf4bc5

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 b48e669 commit 0bf4bc5

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
@@ -888,7 +892,7 @@ async def import_test_node(self, dump: str) -> None:
888892
self.server.signal_event(EventType.NODE_ADDED, node)
889893

890894
@api_command(APICommand.CHECK_NODE_UPDATE)
891-
async def check_node_update(self, node_id: int) -> dict | None:
895+
async def check_node_update(self, node_id: int) -> MatterSoftwareVersion | None:
892896
"""
893897
Check if there is an update for a particular node.
894898
@@ -897,12 +901,36 @@ async def check_node_update(self, node_id: int) -> dict | None:
897901
information of the latest update available.
898902
"""
899903

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

902932
@api_command(APICommand.UPDATE_NODE)
903-
async def update_node(
904-
self, node_id: int, software_version: int | str
905-
) -> dict | None:
933+
async def update_node(self, node_id: int, software_version: int | str) -> None:
906934
"""
907935
Update a node to a new software version.
908936
@@ -955,8 +983,6 @@ async def update_node(
955983
)
956984
self._nodes_in_ota.remove(node_id)
957985

958-
return update
959-
960986
async def _check_node_update(
961987
self,
962988
node_id: int,

0 commit comments

Comments
 (0)