|
| 1 | +From d586d15f83c5fb5fff30b7b7a91b0aced387aa5f Mon Sep 17 00:00:00 2001 |
| 2 | +From: C Freeman <cecille@google.com> |
| 3 | +Date: Wed, 7 Aug 2024 23:05:32 -0400 |
| 4 | +Subject: [PATCH] python: Add direct attribute paths to Read (#34833) |
| 5 | + |
| 6 | +* python: Add direct attribute paths to Read |
| 7 | + |
| 8 | +Supports one particular use case: read one or all endpoints, |
| 9 | +all clusters, specific (global) attribute. See spec 8.9.2.4. This |
| 10 | +is an allowed wildcard construct that is not currently expressable |
| 11 | +in the API. |
| 12 | + |
| 13 | +Test: Used on wildcard read for matter_testing_support. This is |
| 14 | + therefore tested on any test using that decorator - switch |
| 15 | + and timesync. |
| 16 | + |
| 17 | +* Restyled by isort |
| 18 | + |
| 19 | +--------- |
| 20 | + |
| 21 | +Co-authored-by: Restyled.io <commits@restyled.io> |
| 22 | +--- |
| 23 | + src/controller/python/chip/ChipDeviceCtrl.py | 18 +++++++++++++++--- |
| 24 | + src/python_testing/matter_testing_support.py | 1 + |
| 25 | + 2 files changed, 16 insertions(+), 3 deletions(-) |
| 26 | + |
| 27 | +diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py |
| 28 | +index bb4119f1bc..e337bb0c5d 100644 |
| 29 | +--- a/src/controller/python/chip/ChipDeviceCtrl.py |
| 30 | ++++ b/src/controller/python/chip/ChipDeviceCtrl.py |
| 31 | +@@ -1142,8 +1142,12 @@ class ChipDeviceControllerBase(): |
| 32 | + # Wildcard attribute id |
| 33 | + typing.Tuple[int, typing.Type[ClusterObjects.Cluster]], |
| 34 | + # Concrete path |
| 35 | +- typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]] |
| 36 | ++ typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]], |
| 37 | ++ # Directly specified attribute path |
| 38 | ++ ClusterAttribute.AttributePath |
| 39 | + ]): |
| 40 | ++ if isinstance(pathTuple, ClusterAttribute.AttributePath): |
| 41 | ++ return pathTuple |
| 42 | + if pathTuple == ('*') or pathTuple == (): |
| 43 | + # Wildcard |
| 44 | + return ClusterAttribute.AttributePath() |
| 45 | +@@ -1228,7 +1232,9 @@ class ChipDeviceControllerBase(): |
| 46 | + # Wildcard attribute id |
| 47 | + typing.Tuple[int, typing.Type[ClusterObjects.Cluster]], |
| 48 | + # Concrete path |
| 49 | +- typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]] |
| 50 | ++ typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]], |
| 51 | ++ # Directly specified attribute path |
| 52 | ++ ClusterAttribute.AttributePath |
| 53 | + ]] = None, |
| 54 | + dataVersionFilters: typing.List[typing.Tuple[int, typing.Type[ClusterObjects.Cluster], int]] = None, events: typing.List[ |
| 55 | + typing.Union[ |
| 56 | +@@ -1266,6 +1272,8 @@ class ChipDeviceControllerBase(): |
| 57 | + ReadAttribute(1, [ Clusters.BasicInformation ] ) -- case 5 above. |
| 58 | + ReadAttribute(1, [ (1, Clusters.BasicInformation.Attributes.Location ] ) -- case 1 above. |
| 59 | + |
| 60 | ++ An AttributePath can also be specified directly by [chip.cluster.Attribute.AttributePath(...)] |
| 61 | ++ |
| 62 | + dataVersionFilters: A list of tuples of (endpoint, cluster, data version). |
| 63 | + |
| 64 | + events: A list of tuples of varying types depending on the type of read being requested: |
| 65 | +@@ -1326,7 +1334,9 @@ class ChipDeviceControllerBase(): |
| 66 | + # Wildcard attribute id |
| 67 | + typing.Tuple[int, typing.Type[ClusterObjects.Cluster]], |
| 68 | + # Concrete path |
| 69 | +- typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]] |
| 70 | ++ typing.Tuple[int, typing.Type[ClusterObjects.ClusterAttributeDescriptor]], |
| 71 | ++ # Directly specified attribute path |
| 72 | ++ ClusterAttribute.AttributePath |
| 73 | + ]], dataVersionFilters: typing.List[typing.Tuple[int, typing.Type[ClusterObjects.Cluster], int]] = None, |
| 74 | + returnClusterObject: bool = False, |
| 75 | + reportInterval: typing.Tuple[int, int] = None, |
| 76 | +@@ -1350,6 +1360,8 @@ class ChipDeviceControllerBase(): |
| 77 | + ReadAttribute(1, [ Clusters.BasicInformation ] ) -- case 5 above. |
| 78 | + ReadAttribute(1, [ (1, Clusters.BasicInformation.Attributes.Location ] ) -- case 1 above. |
| 79 | + |
| 80 | ++ An AttributePath can also be specified directly by [chip.cluster.Attribute.AttributePath(...)] |
| 81 | ++ |
| 82 | + returnClusterObject: This returns the data as consolidated cluster objects, with all attributes for a cluster inside |
| 83 | + a single cluster-wide cluster object. |
| 84 | + |
| 85 | +diff --git a/src/python_testing/matter_testing_support.py b/src/python_testing/matter_testing_support.py |
| 86 | +index a3bd5d2837..93a89192dc 100644 |
| 87 | +--- a/src/python_testing/matter_testing_support.py |
| 88 | ++++ b/src/python_testing/matter_testing_support.py |
| 89 | +@@ -53,6 +53,7 @@ import chip.logging |
| 90 | + import chip.native |
| 91 | + from chip import discovery |
| 92 | + from chip.ChipStack import ChipStack |
| 93 | ++from chip.clusters import Attribute |
| 94 | + from chip.clusters import ClusterObjects as ClusterObjects |
| 95 | + from chip.clusters.Attribute import EventReadResult, SubscriptionTransaction |
| 96 | + from chip.exceptions import ChipStackError |
| 97 | +-- |
| 98 | +2.46.0 |
| 99 | + |
0 commit comments