From 2ba04957df706808c8d29e8515559b6d9946aaf8 Mon Sep 17 00:00:00 2001 From: Yunhan Wang Date: Mon, 15 Nov 2021 12:55:39 -0800 Subject: [PATCH 1/3] add event codegen for python --- .../templates/app/cluster-objects.zapt | 4 +- .../python/chip/clusters/ClusterObjects.py | 57 +++++++++++++++++++ .../templates/python-cluster-Objects-py.zapt | 23 ++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/src/app/zap-templates/templates/app/cluster-objects.zapt b/src/app/zap-templates/templates/app/cluster-objects.zapt index 658ea3e37235ab..89136aecb85e37 100644 --- a/src/app/zap-templates/templates/app/cluster-objects.zapt +++ b/src/app/zap-templates/templates/app/cluster-objects.zapt @@ -195,8 +195,8 @@ enum class Fields { struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::{{asUpperCamelCase priority}}; - static constexpr EventId eventId = {{asMEI manufacturerCode code}}; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::{{asUpperCamelCase parent.name}}::Id; } {{#zcl_event_fields}} diff --git a/src/controller/python/chip/clusters/ClusterObjects.py b/src/controller/python/chip/clusters/ClusterObjects.py index d8d6b78aad0961..5b8c8ad56faa15 100644 --- a/src/controller/python/chip/clusters/ClusterObjects.py +++ b/src/controller/python/chip/clusters/ClusterObjects.py @@ -210,3 +210,60 @@ def _cluster_object(cls) -> ClusterObject: ) ], bases=(ClusterObject,)) + + +class ClusterEventDescriptor: + ''' + The ClusterEventDescriptor is used for holding an event's metadata like its cluster id, event id and its type. + + Users should not initialize an object based on this class. Instead, users should pass the subclass objects to tell some methods what they want. + + 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. + ''' + @classmethod + def ToTLV(cls, tag: Union[int, None], value): + writer = tlv.TLVWriter() + wrapped_value = cls._cluster_object(Value=value) + cls.event_type.PutFieldToTLV(tag, + asdict(wrapped_value)['Value'], writer, '') + return writer.encoding + + @classmethod + def FromTLV(cls, tlvBuffer: bytes): + obj_class = cls._cluster_object + return obj_class.FromDict(obj_class.descriptor.TagDictToLabelDict('', {0: tlv.TLVReader(tlvBuffer).get().get('Any', {})})).Value + + @classmethod + def FromTagDictOrRawValue(cls, val: Any): + obj_class = cls._cluster_object + return obj_class.FromDict(obj_class.descriptor.TagDictToLabelDict('', {0: val})).Value + + @ChipUtility.classproperty + def cluster_id(self) -> int: + raise NotImplementedError() + + @ChipUtility.classproperty + def event_id(self) -> int: + raise NotImplementedError() + + @ChipUtility.classproperty + def event_type(cls) -> ClusterObjectFieldDescriptor: + raise NotImplementedError() + + @ChipUtility.classproperty + def _cluster_object(cls) -> ClusterObject: + return make_dataclass('InternalClass', + [ + ('Value', List[cls.event_type.Type] + if cls.event_type.IsArray else cls.event_type.Type, field(default=None)), + ('descriptor', ClassVar[ClusterObjectDescriptor], + field( + default=ClusterObjectDescriptor( + Fields=[ClusterObjectFieldDescriptor( + Label='Value', Tag=0, Type=cls.event_type.Type, IsArray=cls.event_type.IsArray)] + ) + ) + ) + ], + bases=(ClusterObject,)) + diff --git a/src/controller/python/templates/python-cluster-Objects-py.zapt b/src/controller/python/templates/python-cluster-Objects-py.zapt index 4fad616d1dbed5..21b8da7ba10077 100644 --- a/src/controller/python/templates/python-cluster-Objects-py.zapt +++ b/src/controller/python/templates/python-cluster-Objects-py.zapt @@ -108,5 +108,28 @@ class {{asUpperCamelCase name}}(Cluster): {{/zcl_attributes_server}} +{{#zcl_events}} +{{#first}} + class Events: +{{/first}} + @dataclass + class {{asUpperCamelCase name}}(ClusterEvent): + cluster_id: typing.ClassVar[int] = {{ asHex parent.code 4 }} + event_id: typing.ClassVar[int] = {{asMEI manufacturerCode code}} + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields = [ + {{#zcl_event_fields}} + ClusterObjectFieldDescriptor(Label="{{ asLowerCamelCase name }}", Tag={{ fieldIdentifier }}, Type={{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.parent.name)}}{{#if isArray}}, IsArray=True{{/if}}), + {{/zcl_event_fields}} + ]) + + {{#zcl_event_fields}} + {{ asLowerCamelCase name }}: {{#if isArray}}typing.List[{{/if}}'{{zapTypeToPythonClusterObjectType type ns=(asUpperCamelCase parent.parent.name)}}'{{#if isArray}}]{{/if}} = None + {{/zcl_event_fields}} + +{{/zcl_events}} {{/zcl_clusters}} From 93068acb0b886e1dfd017f28a9dab48d08f423ae Mon Sep 17 00:00:00 2001 From: Yunhan Wang Date: Mon, 15 Nov 2021 13:00:53 -0800 Subject: [PATCH 2/3] run codegen --- .../python/chip/clusters/Objects.py | 386 ++++++++++++++++++ .../zap-generated/cluster-objects.h | 112 ++--- 2 files changed, 442 insertions(+), 56 deletions(-) diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index 9dace1e78c97c2..13e91031170a45 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -6603,6 +6603,76 @@ def attribute_id(cls) -> int: def attribute_type(cls) -> ClusterObjectFieldDescriptor: return ClusterObjectFieldDescriptor(Type=uint) + class Events: + @dataclass + class HardwareFaultChange(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0033 + event_id: typing.ClassVar[int] = 0x00000000 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="current", Tag=0, Type=GeneralDiagnostics.Enums.HardwareFaultType, IsArray=True), + ClusterObjectFieldDescriptor( + Label="previous", Tag=1, Type=GeneralDiagnostics.Enums.HardwareFaultType, IsArray=True), + ]) + + current: typing.List['GeneralDiagnostics.Enums.HardwareFaultType'] = None + previous: typing.List['GeneralDiagnostics.Enums.HardwareFaultType'] = None + + @dataclass + class RadioFaultChange(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0033 + event_id: typing.ClassVar[int] = 0x00000001 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="current", Tag=0, Type=GeneralDiagnostics.Enums.RadioFaultType, IsArray=True), + ClusterObjectFieldDescriptor( + Label="previous", Tag=1, Type=GeneralDiagnostics.Enums.RadioFaultType, IsArray=True), + ]) + + current: typing.List['GeneralDiagnostics.Enums.RadioFaultType'] = None + previous: typing.List['GeneralDiagnostics.Enums.RadioFaultType'] = None + + @dataclass + class NetworkFaultChange(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0033 + event_id: typing.ClassVar[int] = 0x00000002 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="current", Tag=0, Type=GeneralDiagnostics.Enums.NetworkFaultType, IsArray=True), + ClusterObjectFieldDescriptor( + Label="previous", Tag=1, Type=GeneralDiagnostics.Enums.NetworkFaultType, IsArray=True), + ]) + + current: typing.List['GeneralDiagnostics.Enums.NetworkFaultType'] = None + previous: typing.List['GeneralDiagnostics.Enums.NetworkFaultType'] = None + + @dataclass + class BootReason(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0033 + event_id: typing.ClassVar[int] = 0x00000003 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="bootReason", Tag=0, Type=GeneralDiagnostics.Enums.BootReasonType), + ]) + + bootReason: 'GeneralDiagnostics.Enums.BootReasonType' = None + @dataclass class SoftwareDiagnostics(Cluster): @@ -6743,6 +6813,22 @@ def attribute_id(cls) -> int: def attribute_type(cls) -> ClusterObjectFieldDescriptor: return ClusterObjectFieldDescriptor(Type=uint) + class Events: + @dataclass + class SoftwareFault(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0034 + event_id: typing.ClassVar[int] = 0x00000000 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="softwareFault", Tag=0, Type=SoftwareDiagnostics.Structs.SoftwareFault), + ]) + + softwareFault: 'SoftwareDiagnostics.Structs.SoftwareFault' = None + @dataclass class ThreadNetworkDiagnostics(Cluster): @@ -7778,6 +7864,22 @@ def attribute_id(cls) -> int: def attribute_type(cls) -> ClusterObjectFieldDescriptor: return ClusterObjectFieldDescriptor(Type=uint) + class Events: + @dataclass + class ConnectionStatus(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0035 + event_id: typing.ClassVar[int] = 0x00000000 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="connectionStatus", Tag=0, Type=ThreadNetworkDiagnostics.Enums.ThreadConnectionStatus), + ]) + + connectionStatus: 'ThreadNetworkDiagnostics.Enums.ThreadConnectionStatus' = None + @dataclass class WiFiNetworkDiagnostics(Cluster): @@ -8019,6 +8121,55 @@ def attribute_id(cls) -> int: def attribute_type(cls) -> ClusterObjectFieldDescriptor: return ClusterObjectFieldDescriptor(Type=uint) + class Events: + @dataclass + class Disconnection(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0036 + event_id: typing.ClassVar[int] = 0x00000000 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="reasonCode", Tag=0, Type=uint), + ]) + + reasonCode: 'uint' = None + + @dataclass + class AssociationFailure(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0036 + event_id: typing.ClassVar[int] = 0x00000001 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="associationFailure", Tag=0, Type=WiFiNetworkDiagnostics.Enums.AssociationFailureCause), + ClusterObjectFieldDescriptor( + Label="status", Tag=1, Type=uint), + ]) + + associationFailure: 'WiFiNetworkDiagnostics.Enums.AssociationFailureCause' = None + status: 'uint' = None + + @dataclass + class ConnectionStatus(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0036 + event_id: typing.ClassVar[int] = 0x00000002 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="connectionStatus", Tag=0, Type=WiFiNetworkDiagnostics.Enums.WiFiConnectionStatus), + ]) + + connectionStatus: 'WiFiNetworkDiagnostics.Enums.WiFiConnectionStatus' = None + @dataclass class EthernetNetworkDiagnostics(Cluster): @@ -9121,6 +9272,22 @@ def attribute_id(cls) -> int: def attribute_type(cls) -> ClusterObjectFieldDescriptor: return ClusterObjectFieldDescriptor(Type=uint) + class Events: + @dataclass + class StateChange(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0045 + event_id: typing.ClassVar[int] = 0x00000000 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="stateValue", Tag=0, Type=bool), + ]) + + stateValue: 'bool' = None + @dataclass class ModeSelect(Cluster): @@ -12099,6 +12266,194 @@ def attribute_id(cls) -> int: def attribute_type(cls) -> ClusterObjectFieldDescriptor: return ClusterObjectFieldDescriptor(Type=uint) + class Events: + @dataclass + class SupplyVoltageLow(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000000 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class SupplyVoltageHigh(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000001 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class PowerMissingPhase(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000002 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class SystemPressureLow(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000003 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class SystemPressureHigh(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000004 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class DryRunning(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000005 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class MotorTemperatureHigh(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000006 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class PumpMotorFatalFailure(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000007 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class ElectronicTemperatureHigh(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000008 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class PumpBlocked(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000009 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class SensorFailure(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x0000000A + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class ElectronicNonFatalFailure(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x0000000B + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class ElectronicFatalFailure(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x0000000C + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class GeneralFault(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x0000000D + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class Leakage(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x0000000E + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class AirDetection(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x0000000F + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + + @dataclass + class TurbineOperation(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x0200 + event_id: typing.ClassVar[int] = 0x00000010 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ]) + @dataclass class Thermostat(Cluster): @@ -21965,6 +22320,37 @@ def attribute_id(cls) -> int: def attribute_type(cls) -> ClusterObjectFieldDescriptor: return ClusterObjectFieldDescriptor(Type=uint) + class Events: + @dataclass + class TestEvent(ClusterEvent): + cluster_id: typing.ClassVar[int] = 0x050F + event_id: typing.ClassVar[int] = 0x00000001 + + @ChipUtility.classproperty + def descriptor(cls) -> ClusterObjectDescriptor: + return ClusterObjectDescriptor( + Fields=[ + ClusterObjectFieldDescriptor( + Label="arg1", Tag=1, Type=uint), + ClusterObjectFieldDescriptor( + Label="arg2", Tag=2, Type=TestCluster.Enums.SimpleEnum), + ClusterObjectFieldDescriptor( + Label="arg3", Tag=3, Type=bool), + ClusterObjectFieldDescriptor( + Label="arg4", Tag=4, Type=TestCluster.Structs.SimpleStruct), + ClusterObjectFieldDescriptor( + Label="arg5", Tag=5, Type=TestCluster.Structs.SimpleStruct, IsArray=True), + ClusterObjectFieldDescriptor( + Label="arg6", Tag=6, Type=TestCluster.Enums.SimpleEnum, IsArray=True), + ]) + + arg1: 'uint' = None + arg2: 'TestCluster.Enums.SimpleEnum' = None + arg3: 'bool' = None + arg4: 'TestCluster.Structs.SimpleStruct' = None + arg5: typing.List['TestCluster.Structs.SimpleStruct'] = None + arg6: typing.List['TestCluster.Enums.SimpleEnum'] = None + @dataclass class Messaging(Cluster): diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index 7827e2f86bdd36..59b0bfe5de6f82 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -9142,8 +9142,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Critical; - static constexpr EventId eventId = 0x00000000; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::GeneralDiagnostics::Id; } DataModel::List current; @@ -9178,8 +9178,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Critical; - static constexpr EventId eventId = 0x00000001; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::GeneralDiagnostics::Id; } DataModel::List current; @@ -9214,8 +9214,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Critical; - static constexpr EventId eventId = 0x00000002; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::GeneralDiagnostics::Id; } DataModel::List current; @@ -9249,8 +9249,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Critical; - static constexpr EventId eventId = 0x00000003; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::GeneralDiagnostics::Id; } BootReasonType bootReason; @@ -9445,8 +9445,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000000; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::SoftwareDiagnostics::Id; } Structs::SoftwareFault::Type softwareFault; @@ -10425,8 +10425,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000000; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::ThreadNetworkDiagnostics::Id; } ThreadConnectionStatus connectionStatus; @@ -10727,8 +10727,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000000; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::WiFiNetworkDiagnostics::Id; } uint16_t reasonCode; @@ -10761,8 +10761,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000001; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::WiFiNetworkDiagnostics::Id; } AssociationFailureCause associationFailure; @@ -10796,8 +10796,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000002; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::WiFiNetworkDiagnostics::Id; } WiFiConnectionStatus connectionStatus; @@ -12295,8 +12295,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000000; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::BooleanState::Id; } bool stateValue; @@ -16430,8 +16430,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000000; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16458,8 +16458,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000001; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16486,8 +16486,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000002; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16514,8 +16514,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000003; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16542,8 +16542,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000004; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16570,8 +16570,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Critical; - static constexpr EventId eventId = 0x00000005; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16598,8 +16598,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000006; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16626,8 +16626,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Critical; - static constexpr EventId eventId = 0x00000007; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16654,8 +16654,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000008; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16682,8 +16682,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Critical; - static constexpr EventId eventId = 0x00000009; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16710,8 +16710,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x0000000A; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16738,8 +16738,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x0000000B; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16766,8 +16766,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Critical; - static constexpr EventId eventId = 0x0000000C; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16794,8 +16794,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x0000000D; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16822,8 +16822,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x0000000E; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16850,8 +16850,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x0000000F; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -16878,8 +16878,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000010; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::PumpConfigurationAndControl::Id; } CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -28766,8 +28766,8 @@ enum class Fields struct Type { public: - static constexpr PriorityLevel priorityLevel = PriorityLevel::Info; - static constexpr EventId eventId = 0x00000001; + static constexpr PriorityLevel GetPriorityLevel() { return kPriorityLevel; } + static constexpr EventId GetEventId() { return kEventId; } static constexpr ClusterId GetClusterId() { return Clusters::TestCluster::Id; } uint8_t arg1; From 1e3fc7649f24334214b61501130034732399afb8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 15 Nov 2021 21:04:21 +0000 Subject: [PATCH 3/3] Restyled by autopep8 --- src/controller/python/chip/clusters/ClusterObjects.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/controller/python/chip/clusters/ClusterObjects.py b/src/controller/python/chip/clusters/ClusterObjects.py index 5b8c8ad56faa15..c3260e24364dfa 100644 --- a/src/controller/python/chip/clusters/ClusterObjects.py +++ b/src/controller/python/chip/clusters/ClusterObjects.py @@ -225,7 +225,7 @@ def ToTLV(cls, tag: Union[int, None], value): writer = tlv.TLVWriter() wrapped_value = cls._cluster_object(Value=value) cls.event_type.PutFieldToTLV(tag, - asdict(wrapped_value)['Value'], writer, '') + asdict(wrapped_value)['Value'], writer, '') return writer.encoding @classmethod @@ -255,15 +255,14 @@ def _cluster_object(cls) -> ClusterObject: return make_dataclass('InternalClass', [ ('Value', List[cls.event_type.Type] - if cls.event_type.IsArray else cls.event_type.Type, field(default=None)), + if cls.event_type.IsArray else cls.event_type.Type, field(default=None)), ('descriptor', ClassVar[ClusterObjectDescriptor], field( default=ClusterObjectDescriptor( Fields=[ClusterObjectFieldDescriptor( Label='Value', Tag=0, Type=cls.event_type.Type, IsArray=cls.event_type.IsArray)] ) - ) - ) + ) + ) ], bases=(ClusterObject,)) -