|
19 | 19 | import ctypes |
20 | 20 | import inspect |
21 | 21 | import logging |
22 | | -import sys |
23 | 22 | from asyncio.futures import Future |
24 | 23 | from ctypes import CFUNCTYPE, POINTER, c_bool, c_char_p, c_size_t, c_uint8, c_uint16, c_uint32, c_void_p, cast, py_object |
25 | 24 | from dataclasses import dataclass |
|
29 | 28 | from ..interaction_model import Status as InteractionModelStatus |
30 | 29 | from ..interaction_model import TestOnlyPyBatchCommandsOverrides, TestOnlyPyOnDoneInfo |
31 | 30 | from ..native import GetLibraryHandle, NativeLibraryHandleMethodArguments, PyChipError |
32 | | -from . import Objects as GeneratedObjects # noqa: F401 |
33 | | -from .ClusterObjects import ClusterCommand |
| 31 | +from . import Objects as GeneratedObjects |
| 32 | +from .ClusterObjects import Cluster, ClusterCommand |
34 | 33 |
|
35 | 34 | logger = logging.getLogger('matter.cluster.Command') |
36 | 35 | logger.setLevel(logging.ERROR) |
@@ -70,17 +69,12 @@ def FindCommandClusterObject(isClientSideCommand: bool, path: CommandPath): |
70 | 69 |
|
71 | 70 | Returns the type of the cluster object if one is found. Otherwise, returns None. |
72 | 71 | ''' |
73 | | - for clusterName, obj in inspect.getmembers(sys.modules['matter.clusters.Objects']): |
74 | | - if ('matter.clusters.Objects' in str(obj)) and inspect.isclass(obj): |
75 | | - for objName, subclass in inspect.getmembers(obj): |
76 | | - if inspect.isclass(subclass) and (('Commands') in str(subclass)): |
77 | | - for commandName, command in inspect.getmembers(subclass): |
78 | | - if inspect.isclass(command): |
79 | | - for name, field in inspect.getmembers(command): |
80 | | - if ('__dataclass_fields__' in name): |
81 | | - if (field['cluster_id'].default == path.ClusterId) and (field['command_id'].default == |
82 | | - path.CommandId) and (field['is_client'].default == isClientSideCommand): |
83 | | - return eval('GeneratedObjects.' + clusterName + '.Commands.' + commandName) |
| 72 | + for clusterName in GeneratedObjects.__all__: |
| 73 | + obj = getattr(GeneratedObjects, clusterName) |
| 74 | + if issubclass(obj, Cluster) and obj.id == path.ClusterId: |
| 75 | + for _, cmd in inspect.getmembers(getattr(obj, "Commands", None), inspect.isclass): |
| 76 | + if issubclass(cmd, ClusterCommand) and cmd.command_id == path.CommandId and cmd.is_client == isClientSideCommand: |
| 77 | + return cmd |
84 | 78 | return None |
85 | 79 |
|
86 | 80 |
|
|
0 commit comments