17
17
18
18
#include " energy-preference-server.h"
19
19
20
- #include < app/util/af.h>
21
-
22
20
#include < app/util/attribute-storage.h>
23
21
24
22
#include < app-common/zap-generated/attributes/Accessors.h>
25
23
#include < app-common/zap-generated/callback.h>
26
24
#include < app-common/zap-generated/cluster-objects.h>
27
25
#include < app-common/zap-generated/ids/Attributes.h>
28
- #include < app/CommandHandler.h>
29
26
#include < app/ConcreteAttributePath.h>
30
27
#include < app/ConcreteCommandPath.h>
31
28
#include < app/util/error-mapping.h>
@@ -52,7 +49,7 @@ class EnergyPrefAttrAccess : public AttributeAccessInterface
52
49
};
53
50
54
51
EnergyPrefAttrAccess gEnergyPrefAttrAccess ;
55
- EnergyPreferenceDelegate * gsDelegate = nullptr ;
52
+ Delegate * gsDelegate = nullptr ;
56
53
57
54
CHIP_ERROR EnergyPrefAttrAccess::Read (const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
58
55
{
@@ -157,22 +154,27 @@ CHIP_ERROR EnergyPrefAttrAccess::Write(const ConcreteDataAttributePath & aPath,
157
154
158
155
} // anonymous namespace
159
156
160
- void SetMatterEnergyPreferencesDelegate (EnergyPreferenceDelegate * aDelegate)
157
+ namespace chip ::app::Clusters::EnergyPreference
158
+ {
159
+
160
+ void SetDelegate (Delegate * aDelegate)
161
161
{
162
162
gsDelegate = aDelegate;
163
163
}
164
164
165
- EnergyPreferenceDelegate * GetMatterEnergyPreferencesDelegate ()
165
+ Delegate * GetDelegate ()
166
166
{
167
167
return gsDelegate;
168
168
}
169
169
170
+ } // Set matter energy preferences delegate
171
+
170
172
Protocols::InteractionModel::Status
171
173
MatterEnergyPreferenceClusterServerPreAttributeChangedCallback (const app::ConcreteAttributePath & attributePath,
172
174
EmberAfAttributeType attributeType, uint16_t size, uint8_t * value)
173
175
{
174
176
EndpointId endpoint = attributePath.mEndpointId ;
175
- EnergyPreferenceDelegate * delegate = GetMatterEnergyPreferencesDelegate ();
177
+ Delegate * delegate = GetDelegate ();
176
178
uint32_t ourFeatureMap;
177
179
bool balanceSupported = (FeatureMap::Get (attributePath.mEndpointId , &ourFeatureMap) == EMBER_ZCL_STATUS_SUCCESS) &&
178
180
((ourFeatureMap & to_underlying (Feature::kEnergyBalance )) != 0 );
@@ -185,27 +187,31 @@ MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const app::Concre
185
187
{
186
188
case CurrentEnergyBalance::Id: {
187
189
if (balanceSupported == false )
190
+ {
188
191
return imcode::UnsupportedAttribute;
192
+ }
189
193
190
- uint8_t index = chip:: Encoding::Get8 (value);
194
+ uint8_t index = Encoding::Get8 (value);
191
195
size_t arraySize = delegate->GetNumEnergyBalances (endpoint);
192
196
if (index >= arraySize)
193
197
{
194
- return imcode::InvalidValue ;
198
+ return imcode::ConstraintError ;
195
199
}
196
200
197
201
return imcode::Success;
198
202
}
199
203
200
204
case CurrentLowPowerModeSensitivity::Id: {
201
205
if (lowPowerSupported == false )
206
+ {
202
207
return imcode::UnsupportedAttribute;
208
+ }
203
209
204
- uint8_t index = chip:: Encoding::Get8 (value);
210
+ uint8_t index = Encoding::Get8 (value);
205
211
size_t arraySize = delegate->GetNumLowPowerModes (endpoint);
206
212
if (index >= arraySize)
207
213
{
208
- return imcode::InvalidValue ;
214
+ return imcode::ConstraintError ;
209
215
}
210
216
211
217
return imcode::Success;
0 commit comments