From e51a48845d05ad45e6acaa883198c985cf30d0e1 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Wed, 5 Jan 2022 07:36:49 -0800 Subject: [PATCH] Add missing parts in Localization Unit cluster (#13316) * Add missing parts in TempUnit cluster * Update gen folders --- .../chip/localization-unit-cluster.xml | 20 +++--- .../python/chip/clusters/Objects.py | 24 ++++++++ .../CHIP/zap-generated/CHIPCallbackBridge.mm | 52 ++++++++++++++++ .../CHIPCallbackBridge_internal.h | 61 +++++++++++++++++++ .../app-common/zap-generated/attribute-id.h | 1 + .../zap-generated/attributes/Accessors.cpp | 31 ++++++++++ .../zap-generated/attributes/Accessors.h | 5 ++ .../zap-generated/cluster-objects.cpp | 3 + .../zap-generated/cluster-objects.h | 20 ++++++ .../app-common/zap-generated/ids/Attributes.h | 4 ++ 10 files changed, 212 insertions(+), 9 deletions(-) diff --git a/src/app/zap-templates/zcl/data-model/chip/localization-unit-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/localization-unit-cluster.xml index dd3ccd094539d4..b5763f7a3da800 100644 --- a/src/app/zap-templates/zcl/data-model/chip/localization-unit-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/localization-unit-cluster.xml @@ -16,8 +16,12 @@ limitations under the License. --> - - + + + + + + General Localization Unit @@ -26,12 +30,10 @@ limitations under the License. true true Nodes should be expected to be deployed to any and all regions of the world. These global regions -may have differing preferences for the units in which values are conveying in communication to a -user. As such, Nodes that visually or audibly convey measurable values to the user need a -mechanism by which they can be configured to use a user’s preferred unit. - - - - + may have differing preferences for the units in which values are conveying in communication to a + user. As such, Nodes that visually or audibly convey measurable values to the user need a + mechanism by which they can be configured to use a user’s preferred unit. + + TemperatureUnit \ No newline at end of file diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index 2100eff0bde986..cf614c17c23897 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -7131,19 +7131,43 @@ class LocalizationUnit(Cluster): def descriptor(cls) -> ClusterObjectDescriptor: return ClusterObjectDescriptor( Fields = [ + ClusterObjectFieldDescriptor(Label="temperatureUnit", Tag=0x00000000, Type=typing.Optional[uint]), ClusterObjectFieldDescriptor(Label="attributeList", Tag=0x0000FFFB, Type=typing.List[uint]), ClusterObjectFieldDescriptor(Label="featureMap", Tag=0x0000FFFC, Type=typing.Optional[uint]), ClusterObjectFieldDescriptor(Label="clusterRevision", Tag=0x0000FFFD, Type=uint), ]) + temperatureUnit: 'typing.Optional[uint]' = None attributeList: 'typing.List[uint]' = None featureMap: 'typing.Optional[uint]' = None clusterRevision: 'uint' = None + class Enums: + class TempUnit(IntEnum): + kFahrenheit = 0x00 + kCelsius = 0x01 + kKelvin = 0x02 + class Attributes: + @dataclass + class TemperatureUnit(ClusterAttributeDescriptor): + @ChipUtility.classproperty + def cluster_id(cls) -> int: + return 0x002D + + @ChipUtility.classproperty + def attribute_id(cls) -> int: + return 0x00000000 + + @ChipUtility.classproperty + def attribute_type(cls) -> ClusterObjectFieldDescriptor: + return ClusterObjectFieldDescriptor(Type=typing.Optional[uint]) + + value: 'typing.Optional[uint]' = None + @dataclass class AttributeList(ClusterAttributeDescriptor): @ChipUtility.classproperty diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm index 51f399c4bde143..ec02391ab9193f 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm @@ -7283,6 +7283,58 @@ } } +void CHIPLocalizationUnitClusterTempUnitAttributeCallbackBridge::OnSuccessFn( + void * context, chip::app::Clusters::LocalizationUnit::TempUnit value) +{ + NSNumber * _Nonnull objCValue; + objCValue = [NSNumber numberWithUnsignedChar:chip::to_underlying(value)]; + DispatchSuccess(context, objCValue); +}; + +void CHIPLocalizationUnitClusterTempUnitAttributeCallbackSubscriptionBridge::OnSubscriptionEstablished(void * context) +{ + auto * self = static_cast(context); + if (!self->mQueue) { + return; + } + + if (self->mEstablishedHandler != nil) { + dispatch_async(self->mQueue, self->mEstablishedHandler); + // On failure, mEstablishedHandler will be cleaned up by our destructor, + // but we can clean it up earlier on successful subscription + // establishment. + self->mEstablishedHandler = nil; + } +} + +void CHIPNullableLocalizationUnitClusterTempUnitAttributeCallbackBridge::OnSuccessFn( + void * context, const chip::app::DataModel::Nullable & value) +{ + NSNumber * _Nullable objCValue; + if (value.IsNull()) { + objCValue = nil; + } else { + objCValue = [NSNumber numberWithUnsignedChar:chip::to_underlying(value.Value())]; + } + DispatchSuccess(context, objCValue); +}; + +void CHIPNullableLocalizationUnitClusterTempUnitAttributeCallbackSubscriptionBridge::OnSubscriptionEstablished(void * context) +{ + auto * self = static_cast(context); + if (!self->mQueue) { + return; + } + + if (self->mEstablishedHandler != nil) { + dispatch_async(self->mQueue, self->mEstablishedHandler); + // On failure, mEstablishedHandler will be cleaned up by our destructor, + // but we can clean it up earlier on successful subscription + // establishment. + self->mEstablishedHandler = nil; + } +} + void CHIPGeneralCommissioningClusterGeneralCommissioningErrorAttributeCallbackBridge::OnSuccessFn( void * context, chip::app::Clusters::GeneralCommissioning::GeneralCommissioningError value) { diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge_internal.h b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge_internal.h index d604a49dacf75c..c77eb3f26a3574 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge_internal.h +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge_internal.h @@ -203,6 +203,9 @@ typedef void (*OtaSoftwareUpdateRequestorClusterUpdateStateEnumAttributeCallback void *, chip::app::Clusters::OtaSoftwareUpdateRequestor::UpdateStateEnum); typedef void (*NullableOtaSoftwareUpdateRequestorClusterUpdateStateEnumAttributeCallback)( void *, const chip::app::DataModel::Nullable &); +typedef void (*LocalizationUnitClusterTempUnitAttributeCallback)(void *, chip::app::Clusters::LocalizationUnit::TempUnit); +typedef void (*NullableLocalizationUnitClusterTempUnitAttributeCallback)( + void *, const chip::app::DataModel::Nullable &); typedef void (*GeneralCommissioningClusterGeneralCommissioningErrorAttributeCallback)( void *, chip::app::Clusters::GeneralCommissioning::GeneralCommissioningError); typedef void (*NullableGeneralCommissioningClusterGeneralCommissioningErrorAttributeCallback)( @@ -6018,6 +6021,64 @@ class CHIPNullableOtaSoftwareUpdateRequestorClusterUpdateStateEnumAttributeCallb SubscriptionEstablishedHandler mEstablishedHandler; }; +class CHIPLocalizationUnitClusterTempUnitAttributeCallbackBridge + : public CHIPCallbackBridge +{ +public: + CHIPLocalizationUnitClusterTempUnitAttributeCallbackBridge(dispatch_queue_t queue, ResponseHandler handler, + CHIPActionBlock action, bool keepAlive = false) : + CHIPCallbackBridge(queue, handler, action, OnSuccessFn, keepAlive){}; + + static void OnSuccessFn(void * context, chip::app::Clusters::LocalizationUnit::TempUnit value); +}; + +class CHIPLocalizationUnitClusterTempUnitAttributeCallbackSubscriptionBridge + : public CHIPLocalizationUnitClusterTempUnitAttributeCallbackBridge +{ +public: + CHIPLocalizationUnitClusterTempUnitAttributeCallbackSubscriptionBridge(dispatch_queue_t queue, ResponseHandler handler, + CHIPActionBlock action, + SubscriptionEstablishedHandler establishedHandler) : + CHIPLocalizationUnitClusterTempUnitAttributeCallbackBridge(queue, handler, action, true), + mEstablishedHandler(establishedHandler) + {} + + static void OnSubscriptionEstablished(void * context); + +private: + SubscriptionEstablishedHandler mEstablishedHandler; +}; + +class CHIPNullableLocalizationUnitClusterTempUnitAttributeCallbackBridge + : public CHIPCallbackBridge +{ +public: + CHIPNullableLocalizationUnitClusterTempUnitAttributeCallbackBridge(dispatch_queue_t queue, ResponseHandler handler, + CHIPActionBlock action, bool keepAlive = false) : + CHIPCallbackBridge(queue, handler, action, OnSuccessFn, + keepAlive){}; + + static void OnSuccessFn(void * context, + const chip::app::DataModel::Nullable & value); +}; + +class CHIPNullableLocalizationUnitClusterTempUnitAttributeCallbackSubscriptionBridge + : public CHIPNullableLocalizationUnitClusterTempUnitAttributeCallbackBridge +{ +public: + CHIPNullableLocalizationUnitClusterTempUnitAttributeCallbackSubscriptionBridge( + dispatch_queue_t queue, ResponseHandler handler, CHIPActionBlock action, + SubscriptionEstablishedHandler establishedHandler) : + CHIPNullableLocalizationUnitClusterTempUnitAttributeCallbackBridge(queue, handler, action, true), + mEstablishedHandler(establishedHandler) + {} + + static void OnSubscriptionEstablished(void * context); + +private: + SubscriptionEstablishedHandler mEstablishedHandler; +}; + class CHIPGeneralCommissioningClusterGeneralCommissioningErrorAttributeCallbackBridge : public CHIPCallbackBridge { diff --git a/zzz_generated/app-common/app-common/zap-generated/attribute-id.h b/zzz_generated/app-common/app-common/zap-generated/attribute-id.h index 23c0e496087fca..afc4f8ff51c769 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attribute-id.h +++ b/zzz_generated/app-common/app-common/zap-generated/attribute-id.h @@ -339,6 +339,7 @@ // Client attributes // Server attributes +#define ZCL_TEMPERATURE_UNIT_ATTRIBUTE_ID (0x0000) // Attribute ids for cluster: Power Source Configuration diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp index a859b22d8a7e7c..11e87c358f6ca8 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp @@ -6570,6 +6570,37 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value) namespace LocalizationUnit { namespace Attributes { +namespace TemperatureUnit { + +EmberAfStatus Get(chip::EndpointId endpoint, uint8_t * value) +{ + using Traits = NumericAttributeTraits; + Traits::StorageType temp; + uint8_t * readable = Traits::ToAttributeStoreRepresentation(temp); + EmberAfStatus status = emberAfReadServerAttribute(endpoint, Clusters::LocalizationUnit::Id, Id, readable, sizeof(temp)); + VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == status, status); + if (!Traits::CanRepresentValue(/* isNullable = */ false, temp)) + { + return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + } + *value = Traits::StorageToWorking(temp); + return status; +} +EmberAfStatus Set(chip::EndpointId endpoint, uint8_t value) +{ + using Traits = NumericAttributeTraits; + if (!Traits::CanRepresentValue(/* isNullable = */ false, value)) + { + return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + } + Traits::StorageType storageValue; + Traits::WorkingToStorage(value, storageValue); + uint8_t * writable = Traits::ToAttributeStoreRepresentation(storageValue); + return emberAfWriteServerAttribute(endpoint, Clusters::LocalizationUnit::Id, Id, writable, ZCL_ENUM8_ATTRIBUTE_TYPE); +} + +} // namespace TemperatureUnit + namespace FeatureMap { EmberAfStatus Get(chip::EndpointId endpoint, uint32_t * value) diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h index f2f6c84aa35382..7c5a59f636f2a5 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h @@ -1201,6 +1201,11 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value); namespace LocalizationUnit { namespace Attributes { +namespace TemperatureUnit { +EmberAfStatus Get(chip::EndpointId endpoint, uint8_t * value); // enum8 +EmberAfStatus Set(chip::EndpointId endpoint, uint8_t value); +} // namespace TemperatureUnit + namespace FeatureMap { EmberAfStatus Get(chip::EndpointId endpoint, uint32_t * value); // bitmap32 EmberAfStatus Set(chip::EndpointId endpoint, uint32_t value); diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp index be254177301560..8695d79361b94b 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp @@ -6384,6 +6384,9 @@ CHIP_ERROR TypeInfo::DecodableType::Decode(TLV::TLVReader & reader, const Concre { switch (path.mAttributeId) { + case Attributes::TemperatureUnit::TypeInfo::GetAttributeId(): + ReturnErrorOnFailure(DataModel::Decode(reader, temperatureUnit)); + break; case Attributes::AttributeList::TypeInfo::GetAttributeId(): ReturnErrorOnFailure(DataModel::Decode(reader, attributeList)); break; 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 729416f93d158a..223e748cd2d752 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 @@ -8946,9 +8946,28 @@ struct TypeInfo } // namespace Attributes } // namespace LocalizationTimeFormat namespace LocalizationUnit { +// Enum for TempUnit +enum class TempUnit : uint8_t +{ + kFahrenheit = 0x00, + kCelsius = 0x01, + kKelvin = 0x02, +}; namespace Attributes { +namespace TemperatureUnit { +struct TypeInfo +{ + using Type = uint8_t; + using DecodableType = uint8_t; + using DecodableArgType = uint8_t; + + static constexpr ClusterId GetClusterId() { return Clusters::LocalizationUnit::Id; } + static constexpr AttributeId GetAttributeId() { return Attributes::TemperatureUnit::Id; } + static constexpr bool MustUseTimedWrite() { return false; } +}; +} // namespace TemperatureUnit namespace AttributeList { struct TypeInfo { @@ -8994,6 +9013,7 @@ struct TypeInfo CHIP_ERROR Decode(TLV::TLVReader & reader, const ConcreteAttributePath & path); + Attributes::TemperatureUnit::TypeInfo::DecodableType temperatureUnit; Attributes::AttributeList::TypeInfo::DecodableType attributeList; Attributes::FeatureMap::TypeInfo::DecodableType featureMap; Attributes::ClusterRevision::TypeInfo::DecodableType clusterRevision; diff --git a/zzz_generated/app-common/app-common/zap-generated/ids/Attributes.h b/zzz_generated/app-common/app-common/zap-generated/ids/Attributes.h index 3bc731181f2d4d..bfb90cd718b185 100644 --- a/zzz_generated/app-common/app-common/zap-generated/ids/Attributes.h +++ b/zzz_generated/app-common/app-common/zap-generated/ids/Attributes.h @@ -1130,6 +1130,10 @@ static constexpr AttributeId Id = Globals::Attributes::ClusterRevision::Id; namespace LocalizationUnit { namespace Attributes { +namespace TemperatureUnit { +static constexpr AttributeId Id = 0x00000000; +} // namespace TemperatureUnit + namespace AttributeList { static constexpr AttributeId Id = Globals::Attributes::AttributeList::Id; } // namespace AttributeList