Skip to content

Commit bc10cea

Browse files
Merge pull request #7 from marcelveldt/patch-1
Add patch to create lookup dicts
2 parents 51ec23f + 708cbb8 commit bc10cea

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ jobs:
9191
patch -p1 < ../0003-Use-data-as-platform-storage-location.patch
9292
patch -p1 < ../0004-Drop-pygobject-dependency.patch
9393
patch -p1 < ../0005-Fix-Objects.py-for-Python-3.11-compatibility.patch
94+
patch -p1 < ../0006-Add-lookup-dicts-for-clusters-and-attributes.patch
9495
- name: Bootstrap
9596
run: scripts/build/gn_bootstrap.sh
9697
- name: Setup Build, Run Build and Run Tests
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
From ad37e367f4989efb5cd8668e3a086101385d2c2a Mon Sep 17 00:00:00 2001
2+
From: Marcel van der Veldt <m.vanderveldt@outlook.com>
3+
Date: Mon, 20 Feb 2023 19:17:39 +0100
4+
Subject: [PATCH] Add lookup dicts for clusters and attributes
5+
6+
---
7+
.../python/chip/clusters/ClusterObjects.py | 20 +++++++++++++++++++
8+
1 file changed, 20 insertions(+)
9+
10+
diff --git a/src/controller/python/chip/clusters/ClusterObjects.py b/src/controller/python/chip/clusters/ClusterObjects.py
11+
index c3af537da..2d3a73a10 100644
12+
--- a/src/controller/python/chip/clusters/ClusterObjects.py
13+
+++ b/src/controller/python/chip/clusters/ClusterObjects.py
14+
@@ -217,6 +217,10 @@ class ClusterCommand(ClusterObject):
15+
def must_use_timed_invoke(cls) -> bool:
16+
return False
17+
18+
+# The below dictionaries will be filled dynamically
19+
+# and are used for quick lookup/mapping from cluster/attribute id to the correct class
20+
+ALL_CLUSTERS = {}
21+
+ALL_ATTRIBUTES = {}
22+
23+
class Cluster(ClusterObject):
24+
'''
25+
@@ -227,6 +231,13 @@ class Cluster(ClusterObject):
26+
especially the TLV decoding logic. Also ThreadNetworkDiagnostics has an attribute with the same name so we
27+
picked data_version as its name.
28+
'''
29+
+
30+
+ def __init_subclass__(cls, *args, **kwargs) -> None:
31+
+ """Register a subclass."""
32+
+ super().__init_subclass__(*args, **kwargs)
33+
+ # register this cluster in the ALL_CLUSTERS dict for quick lookups
34+
+ ALL_CLUSTERS[cls.id] = cls
35+
+
36+
@property
37+
def data_version(self) -> int:
38+
return self._data_version
39+
@@ -253,6 +264,15 @@ class ClusterAttributeDescriptor:
40+
41+
The implementation of this functions is quite tricky, it will create a cluster object on-the-fly, and use it for actual encode / decode routine to save lines of code.
42+
'''
43+
+
44+
+ def __init_subclass__(cls, *args, **kwargs) -> None:
45+
+ """Register a subclass."""
46+
+ super().__init_subclass__(*args, **kwargs)
47+
+ if cls.cluster_id not in ALL_ATTRIBUTES:
48+
+ ALL_ATTRIBUTES[cls.cluster_id] = {}
49+
+ # register this clusterattribute in the ALL_ATTRIBUTES dict for quick lookups
50+
+ ALL_ATTRIBUTES[cls.cluster_id][cls.attribute_id] = cls
51+
+
52+
@classmethod
53+
def ToTLV(cls, tag: Union[int, None], value):
54+
writer = tlv.TLVWriter()
55+
--
56+
2.37.0 (Apple Git-136)
57+

0 commit comments

Comments
 (0)