Skip to content

Commit fd39d44

Browse files
committed
Some more comments resolved
1 parent e4bb1c7 commit fd39d44

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/app/clusters/energy-preference-server/energy-preference-server.cpp

+10-20
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <app-common/zap-generated/cluster-objects.h>
2525
#include <app-common/zap-generated/ids/Attributes.h>
2626
#include <app/ConcreteAttributePath.h>
27-
#include <app/ConcreteCommandPath.h>
2827
#include <app/util/error-mapping.h>
2928
#include <lib/core/CHIPEncoding.h>
3029

@@ -45,7 +44,6 @@ class EnergyPrefAttrAccess : public AttributeAccessInterface
4544
EnergyPrefAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), EnergyPreference::Id) {}
4645

4746
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
48-
CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override;
4947
};
5048

5149
EnergyPrefAttrAccess gEnergyPrefAttrAccess;
@@ -56,16 +54,16 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
5654
VerifyOrDie(aPath.mClusterId == EnergyPreference::Id);
5755
EndpointId endpoint = aPath.mEndpointId;
5856
uint32_t ourFeatureMap;
59-
bool balanceSupported = (FeatureMap::Get(aPath.mEndpointId, &ourFeatureMap) == EMBER_ZCL_STATUS_SUCCESS) &&
60-
((ourFeatureMap & to_underlying(Feature::kEnergyBalance)) != 0);
61-
bool lowPowerSupported = (ourFeatureMap & to_underlying(Feature::kLowPowerModeSensitivity)) != 0;
57+
const bool featureMapIsGood = FeatureMap::Get(aPath.mEndpointId, &ourFeatureMap) == EMBER_ZCL_STATUS_SUCCESS;
58+
const bool balanceSupported = featureMapIsGood && ((ourFeatureMap & to_underlying(Feature::kEnergyBalance)) != 0);
59+
const bool lowPowerSupported = featureMapIsGood && ((ourFeatureMap & to_underlying(Feature::kLowPowerModeSensitivity)) != 0);
6260

6361
switch (aPath.mAttributeId)
6462
{
6563
case EnergyBalances::Id:
6664
if (!balanceSupported)
6765
{
68-
return aEncoder.EncodeNull();
66+
return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute);
6967
}
7068

7169
if (gsDelegate != nullptr)
@@ -90,7 +88,7 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
9088
case EnergyPriorities::Id:
9189
if (balanceSupported == false)
9290
{
93-
return aEncoder.EncodeNull();
91+
return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute);
9492
}
9593

9694
if (gsDelegate != nullptr)
@@ -115,7 +113,7 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
115113
case LowPowerModeSensitivities::Id:
116114
if (lowPowerSupported == false)
117115
{
118-
return aEncoder.EncodeNull();
116+
return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute);
119117
}
120118

121119
if (gsDelegate != nullptr)
@@ -144,14 +142,6 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
144142
return CHIP_NO_ERROR;
145143
}
146144

147-
CHIP_ERROR EnergyPrefAttrAccess::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder)
148-
{
149-
VerifyOrDie(aPath.mClusterId == EnergyPreference::Id);
150-
151-
// return CHIP_NO_ERROR and just write to the attribute store in default
152-
return CHIP_NO_ERROR;
153-
}
154-
155145
} // anonymous namespace
156146

157147
namespace chip::app::Clusters::EnergyPreference
@@ -170,15 +160,15 @@ Delegate * GetDelegate()
170160
} // Set matter energy preferences delegate
171161

172162
Protocols::InteractionModel::Status
173-
MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const app::ConcreteAttributePath & attributePath,
163+
MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const ConcreteAttributePath & attributePath,
174164
EmberAfAttributeType attributeType, uint16_t size, uint8_t * value)
175165
{
176166
EndpointId endpoint = attributePath.mEndpointId;
177167
Delegate * delegate = GetDelegate();
178168
uint32_t ourFeatureMap;
179-
bool balanceSupported = (FeatureMap::Get(attributePath.mEndpointId, &ourFeatureMap) == EMBER_ZCL_STATUS_SUCCESS) &&
180-
((ourFeatureMap & to_underlying(Feature::kEnergyBalance)) != 0);
181-
bool lowPowerSupported = (ourFeatureMap & to_underlying(Feature::kLowPowerModeSensitivity)) != 0;
169+
const bool featureMapIsGood = FeatureMap::Get(attributePath.mEndpointId, &ourFeatureMap) == EMBER_ZCL_STATUS_SUCCESS;
170+
const bool balanceSupported = featureMapIsGood && ((ourFeatureMap & to_underlying(Feature::kEnergyBalance)) != 0);
171+
const bool lowPowerSupported = featureMapIsGood && ((ourFeatureMap & to_underlying(Feature::kLowPowerModeSensitivity)) != 0);
182172

183173
if (delegate == nullptr)
184174
return imcode::UnsupportedWrite;

0 commit comments

Comments
 (0)