Skip to content

Commit 1b4f11c

Browse files
authored
Handle edgecase where descriptor cluster is missing (#297)
1 parent 99179f8 commit 1b4f11c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

matter_server/client/models/node.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,13 @@ def update(self, attributes_data: dict[str, Any]) -> None:
197197
for attribute_path, attribute_value in attributes_data.items():
198198
self.set_attribute_value(attribute_path, attribute_value)
199199
# extract device types from Descriptor Cluster
200-
cluster = self.get_cluster(Clusters.Descriptor)
201-
assert cluster is not None
202-
for dev_info in cluster.deviceTypeList: # type: ignore[unreachable]
203-
device_type = DEVICE_TYPES.get(dev_info.deviceType)
204-
if device_type is None:
205-
LOGGER.debug("Found unknown device type %s", dev_info)
206-
continue
207-
self.device_types.add(device_type)
200+
if cluster := self.get_cluster(Clusters.Descriptor):
201+
for dev_info in cluster.deviceTypeList: # type: ignore[unreachable]
202+
device_type = DEVICE_TYPES.get(dev_info.deviceType)
203+
if device_type is None:
204+
LOGGER.debug("Found unknown device type %s", dev_info)
205+
continue
206+
self.device_types.add(device_type)
208207

209208
def __repr__(self) -> str:
210209
"""Return the representation."""
@@ -326,7 +325,13 @@ def update(self, node_data: MatterNodeData) -> None:
326325
# (as that will also use partsList to indicate its child's)
327326
continue
328327
descriptor = endpoint.get_cluster(Clusters.Descriptor)
329-
assert descriptor is not None
328+
if descriptor is None:
329+
LOGGER.warning(
330+
"Found endpoint without a Descriptor: Node %s, endpoint %s",
331+
self.node_id,
332+
endpoint.endpoint_id,
333+
)
334+
continue
330335
if descriptor.partsList: # type: ignore[unreachable]
331336
for endpoint_id in descriptor.partsList:
332337
self._composed_endpoints[endpoint_id] = endpoint.endpoint_id

0 commit comments

Comments
 (0)