Skip to content

Commit 2898361

Browse files
cecillerestyled-commits
authored andcommitted
python: Add direct attribute paths to Read (project-chip#34833)
* python: Add direct attribute paths to Read Supports one particular use case: read one or all endpoints, all clusters, specific (global) attribute. See spec 8.9.2.4. This is an allowed wildcard construct that is not currently expressable in the API. Test: Used on wildcard read for matter_testing_support. This is therefore tested on any test using that decorator - switch and timesync. * Restyled by isort --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 8b65482 commit 2898361

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/controller/python/chip/ChipDeviceCtrl.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -1351,8 +1351,12 @@ def _parseAttributePathTuple(self, pathTuple: typing.Union[
13511351
# Wildcard attribute id
13521352
typing.Tuple[int, typing.Type[ClusterObjects.Cluster]],
13531353
# Concrete path
1354-
typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]]
1354+
typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]],
1355+
# Directly specified attribute path
1356+
ClusterAttribute.AttributePath
13551357
]):
1358+
if isinstance(pathTuple, ClusterAttribute.AttributePath):
1359+
return pathTuple
13561360
if pathTuple == ('*') or pathTuple == ():
13571361
# Wildcard
13581362
return ClusterAttribute.AttributePath()
@@ -1437,7 +1441,9 @@ async def Read(self, nodeid: int, attributes: typing.Optional[typing.List[typing
14371441
# Wildcard attribute id
14381442
typing.Tuple[int, typing.Type[ClusterObjects.Cluster]],
14391443
# Concrete path
1440-
typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]]
1444+
typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]],
1445+
# Directly specified attribute path
1446+
ClusterAttribute.AttributePath
14411447
]]] = None,
14421448
dataVersionFilters: typing.Optional[typing.List[typing.Tuple[int, typing.Type[ClusterObjects.Cluster], int]]] = None, events: typing.Optional[typing.List[
14431449
typing.Union[
@@ -1476,6 +1482,8 @@ async def Read(self, nodeid: int, attributes: typing.Optional[typing.List[typing
14761482
ReadAttribute(1, [ Clusters.BasicInformation ] ) -- case 5 above.
14771483
ReadAttribute(1, [ (1, Clusters.BasicInformation.Attributes.Location ] ) -- case 1 above.
14781484
1485+
An AttributePath can also be specified directly by [chip.cluster.Attribute.AttributePath(...)]
1486+
14791487
dataVersionFilters: A list of tuples of (endpoint, cluster, data version).
14801488
14811489
events: A list of tuples of varying types depending on the type of read being requested:
@@ -1543,7 +1551,9 @@ async def ReadAttribute(self, nodeid: int, attributes: typing.Optional[typing.Li
15431551
# Wildcard attribute id
15441552
typing.Tuple[int, typing.Type[ClusterObjects.Cluster]],
15451553
# Concrete path
1546-
typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]]
1554+
typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]],
1555+
# Directly specified attribute path
1556+
ClusterAttribute.AttributePath
15471557
]]], dataVersionFilters: typing.Optional[typing.List[typing.Tuple[int, typing.Type[ClusterObjects.Cluster], int]]] = None,
15481558
returnClusterObject: bool = False,
15491559
reportInterval: typing.Optional[typing.Tuple[int, int]] = None,
@@ -1568,6 +1578,8 @@ async def ReadAttribute(self, nodeid: int, attributes: typing.Optional[typing.Li
15681578
ReadAttribute(1, [ Clusters.BasicInformation ] ) -- case 5 above.
15691579
ReadAttribute(1, [ (1, Clusters.BasicInformation.Attributes.Location ] ) -- case 1 above.
15701580
1581+
An AttributePath can also be specified directly by [chip.cluster.Attribute.AttributePath(...)]
1582+
15711583
returnClusterObject: This returns the data as consolidated cluster objects, with all attributes for a cluster inside
15721584
a single cluster-wide cluster object.
15731585

src/python_testing/matter_testing_support.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import chip.native
5454
from chip import discovery
5555
from chip.ChipStack import ChipStack
56+
from chip.clusters import Attribute
5657
from chip.clusters import ClusterObjects as ClusterObjects
5758
from chip.clusters.Attribute import EventReadResult, SubscriptionTransaction, TypedAttributePath
5859
from chip.exceptions import ChipStackError
@@ -1863,7 +1864,7 @@ async def get_accepted_endpoints_for_test(self: MatterBaseTest, accept_function:
18631864
18641865
Returns a list of endpoints on which the test should be run given the accept_function for the test.
18651866
"""
1866-
wildcard = await self.default_controller.Read(self.dut_node_id, [()])
1867+
wildcard = await self.default_controller.Read(self.dut_node_id, [(Clusters.Descriptor), Attribute.AttributePath(None, None, GlobalAttributeIds.ATTRIBUTE_LIST_ID), Attribute.AttributePath(None, None, GlobalAttributeIds.FEATURE_MAP_ID), Attribute.AttributePath(None, None, GlobalAttributeIds.ACCEPTED_COMMAND_LIST_ID)])
18671868
return [e for e in wildcard.attributes.keys() if accept_function(wildcard, e)]
18681869

18691870

0 commit comments

Comments
 (0)