Skip to content

Commit 56f6e3a

Browse files
authored
Prevent duplicate interviews (#539)
1 parent 459b203 commit 56f6e3a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

matter_server/common/helpers/util.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utils for Matter server (and client)."""
2+
23
from __future__ import annotations
34

45
import base64
@@ -257,6 +258,7 @@ def dataclass_from_dict(cls: type[_T], dict_obj: dict, strict: bool = False) ->
257258
dict_obj.get(field.name),
258259
type_hints[field.name],
259260
field.default,
261+
allow_none=not strict,
260262
)
261263
for field in dc_fields
262264
if field.init

matter_server/server/device_controller.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from matter_server.server.helpers.attributes import parse_attributes_from_read_result
2525
from matter_server.server.helpers.utils import ping_ip
2626

27-
from ..common.const import SCHEMA_VERSION
2827
from ..common.errors import (
2928
NodeCommissionFailed,
3029
NodeInterviewFailed,
@@ -156,11 +155,23 @@ async def start(self) -> None:
156155
# as this can no longer happen.
157156
orphaned_nodes.add(node_id_str)
158157
continue
159-
if node_dict.get("interview_version") != SCHEMA_VERSION:
160-
# Invalidate node attributes data if schema mismatch,
161-
# the node will automatically be scheduled for re-interview.
162-
node_dict["attributes"] = {}
163-
node = dataclass_from_dict(MatterNodeData, node_dict)
158+
try:
159+
node = dataclass_from_dict(MatterNodeData, node_dict, strict=True)
160+
except (KeyError, ValueError):
161+
# constructing MatterNodeData from the cached dict is not possible,
162+
# revert to a fallback object and the node will be re-interviewed
163+
node = MatterNodeData(
164+
node_id=node_id,
165+
date_commissioned=node_dict.get(
166+
"date_commissioned",
167+
datetime(1970, 1, 1),
168+
),
169+
last_interview=node_dict.get(
170+
"last_interview",
171+
datetime(1970, 1, 1),
172+
),
173+
interview_version=0,
174+
)
164175
# always mark node as unavailable at startup until subscriptions are ready
165176
node.available = False
166177
self._nodes[node_id] = node

0 commit comments

Comments
 (0)