Skip to content

Commit b121f07

Browse files
committed
add an ALL_EVENTS
1 parent e96ddd9 commit b121f07

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/controller/python/chip/clusters/ClusterObjects.py

+14
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def descriptor(cls):
214214
# These need to be separate because there can be overlap in command ids for commands and responses.
215215
ALL_ACCEPTED_COMMANDS: typing.Dict = {}
216216
ALL_GENERATED_COMMANDS: typing.Dict = {}
217+
ALL_EVENTS: typing.Dict = {}
217218

218219

219220
class ClusterCommand(ClusterObject):
@@ -369,6 +370,19 @@ def _cluster_object(cls) -> ClusterObject:
369370

370371

371372
class ClusterEvent(ClusterObject):
373+
def __init_subclass__(cls, *args, **kwargs) -> None:
374+
"""Register a subclass."""
375+
super().__init_subclass__(*args, **kwargs)
376+
try:
377+
if cls.event_id not in ALL_EVENTS:
378+
ALL_EVENTS[cls.event_id] = {}
379+
# register this clusterattribute in the ALL_ATTRIBUTES dict for quick lookups
380+
ALL_EVENTS[cls.cluster_id][cls.event_id] = cls
381+
except NotImplementedError:
382+
# handle case where the ClusterAttribute class is not (fully) subclassed
383+
# and accessing the id property throws a NotImplementedError.
384+
pass
385+
372386
@ChipUtility.classproperty
373387
def cluster_id(self) -> int:
374388
raise NotImplementedError()

0 commit comments

Comments
 (0)