diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index 8264379ee5b98a..4e7c234a81b6c8 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -4334,7 +4334,7 @@ provisional cluster EnergyEvse = 153 { /** This cluster provides an interface to specify preferences for how devices should consume energy. */ cluster EnergyPreference = 155 { - revision 1; // NOTE: Default/not specifically set + revision 1; enum EnergyPriorityEnum : enum8 { kComfort = 0; diff --git a/examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp b/examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp index 0e511180d04656..4d0a6490533a28 100644 --- a/examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp @@ -4,37 +4,23 @@ using namespace chip; using namespace chip::app::Clusters::EnergyPreference; using namespace chip::app::Clusters::EnergyPreference::Structs; -static constexpr const char * kEfficientLabel = "Efficient"; -static constexpr const char * kComfortLabel = "Comfort"; - static BalanceStruct::Type gsEnergyBalances[] = { - { .step = 0, .label = Optional(chip::CharSpan(kEfficientLabel, strlen(kEfficientLabel))) }, + { .step = 0, .label = Optional("Efficient"_span) }, { .step = 50, .label = Optional() }, - { .step = 100, .label = Optional(chip::CharSpan(kComfortLabel, strlen(kComfortLabel))) }, + { .step = 100, .label = Optional("Comfort"_span) }, }; -static constexpr const char * k1MinuteLabel = "1 Minute"; -static constexpr const char * k5MinutesLabel = "5 Minutes"; -static constexpr const char * k10MinutesLabel = "10 Minutes"; -static constexpr const char * k15MinutesLabel = "15 Minutes"; -static constexpr const char * k20MinutesLabel = "20 Minutes"; -static constexpr const char * k25MinutesLabel = "25 Minutes"; -static constexpr const char * k30MinutesLabel = "30 Minutes"; -static constexpr const char * k60MinutesLabel = "60 Minutes"; -static constexpr const char * k120MinutesLabel = "120 Minutes"; -static constexpr const char * kNeverLabel = "Never"; - static BalanceStruct::Type gsPowerBalances[] = { - { .step = 0, .label = Optional(chip::CharSpan(k1MinuteLabel, strlen(k1MinuteLabel))) }, - { .step = 12, .label = Optional(chip::CharSpan(k5MinutesLabel, strlen(k5MinutesLabel))) }, - { .step = 24, .label = Optional(chip::CharSpan(k10MinutesLabel, strlen(k10MinutesLabel))) }, - { .step = 36, .label = Optional(chip::CharSpan(k15MinutesLabel, strlen(k15MinutesLabel))) }, - { .step = 48, .label = Optional(chip::CharSpan(k20MinutesLabel, strlen(k20MinutesLabel))) }, - { .step = 60, .label = Optional(chip::CharSpan(k25MinutesLabel, strlen(k25MinutesLabel))) }, - { .step = 70, .label = Optional(chip::CharSpan(k30MinutesLabel, strlen(k30MinutesLabel))) }, - { .step = 80, .label = Optional(chip::CharSpan(k60MinutesLabel, strlen(k60MinutesLabel))) }, - { .step = 90, .label = Optional(chip::CharSpan(k120MinutesLabel, strlen(k120MinutesLabel))) }, - { .step = 100, .label = Optional(chip::CharSpan(kNeverLabel, strlen(kNeverLabel))) }, + { .step = 0, .label = Optional("1 Minute"_span) }, + { .step = 12, .label = Optional("5 Minutes"_span) }, + { .step = 24, .label = Optional("10 Minutes"_span) }, + { .step = 36, .label = Optional("15 Minutes"_span) }, + { .step = 48, .label = Optional("20 Minutes"_span) }, + { .step = 60, .label = Optional("25 Minutes"_span) }, + { .step = 70, .label = Optional("30 Minutes"_span) }, + { .step = 80, .label = Optional("60 Minutes"_span) }, + { .step = 90, .label = Optional("120 Minutes"_span) }, + { .step = 100, .label = Optional("Never"_span) }, }; // assumes it'll be the only delegate for it's lifetime. @@ -53,22 +39,24 @@ struct EPrefDelegate : public EnergyPreferenceDelegate EPrefDelegate::EPrefDelegate() : EnergyPreferenceDelegate() { + VerifyOrDie(GetMatterEnergyPreferencesDelegate() == nullptr); SetMatterEnergyPreferencesDelegate(this); } EPrefDelegate::~EPrefDelegate() { + VerifyOrDie(GetMatterEnergyPreferencesDelegate() == this); SetMatterEnergyPreferencesDelegate(nullptr); } size_t EPrefDelegate::GetNumEnergyBalances(chip::EndpointId aEndpoint) { - return (sizeof(gsEnergyBalances) / sizeof(gsEnergyBalances[0])); + return (ArraySize(gsEnergyBalances)); } size_t EPrefDelegate::GetNumLowPowerModes(chip::EndpointId aEndpoint) { - return (sizeof(gsEnergyBalances) / sizeof(gsEnergyBalances[0])); + return (ArraySize(gsEnergyBalances)); } CHIP_ERROR diff --git a/src/app/clusters/energy-preference-server/energy-preference-server.cpp b/src/app/clusters/energy-preference-server/energy-preference-server.cpp index 9c9835f073b031..2ec6074c9c7620 100644 --- a/src/app/clusters/energy-preference-server/energy-preference-server.cpp +++ b/src/app/clusters/energy-preference-server/energy-preference-server.cpp @@ -65,8 +65,8 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A switch (aPath.mAttributeId) { - case EnergyBalances::Id: { - if (balanceSupported == false) + case EnergyBalances::Id: + if (!balanceSupported) { return aEncoder.EncodeNull(); } @@ -90,9 +90,7 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A }); } return CHIP_ERROR_INCORRECT_STATE; - } - break; - case EnergyPriorities::Id: { + case EnergyPriorities::Id: if (balanceSupported == false) { return aEncoder.EncodeNull(); @@ -117,9 +115,7 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A }); } return CHIP_ERROR_INCORRECT_STATE; - } - break; - case LowPowerModeSensitivities::Id: { + case LowPowerModeSensitivities::Id: if (lowPowerSupported == false) { return aEncoder.EncodeNull(); @@ -144,8 +140,6 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A }); } return CHIP_ERROR_INCORRECT_STATE; - } - break; default: // return CHIP_NO_ERROR and just read from the attribute store in default break; } @@ -196,7 +190,10 @@ MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const app::Concre uint8_t index = chip::Encoding::Get8(value); size_t arraySize = delegate->GetNumEnergyBalances(endpoint); if (index >= arraySize) + { return imcode::InvalidValue; + } + return imcode::Success; } @@ -207,7 +204,10 @@ MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const app::Concre uint8_t index = chip::Encoding::Get8(value); size_t arraySize = delegate->GetNumLowPowerModes(endpoint); if (index >= arraySize) + { return imcode::InvalidValue; + } + return imcode::Success; } default: diff --git a/src/app/zap-templates/zcl/data-model/chip/energy-preference-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/energy-preference-cluster.xml index f7a45dfd016b05..7a6764bb95a39d 100644 --- a/src/app/zap-templates/zcl/data-model/chip/energy-preference-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/energy-preference-cluster.xml @@ -22,6 +22,7 @@ limitations under the License. true This cluster provides an interface to specify preferences for how devices should consume energy. + EnergyBalances diff --git a/src/controller/data_model/controller-clusters.matter b/src/controller/data_model/controller-clusters.matter index 326e580d04ec2f..14a2c121c14c44 100644 --- a/src/controller/data_model/controller-clusters.matter +++ b/src/controller/data_model/controller-clusters.matter @@ -4765,7 +4765,7 @@ provisional cluster EnergyEvse = 153 { /** This cluster provides an interface to specify preferences for how devices should consume energy. */ cluster EnergyPreference = 155 { - revision 1; // NOTE: Default/not specifically set + revision 1; enum EnergyPriorityEnum : enum8 { kComfort = 0;