Skip to content

Commit e4bb1c7

Browse files
committed
Addressing some review concerns
1 parent bfc06e1 commit e4bb1c7

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

examples/all-clusters-app/all-clusters-common/src/energy-preference-delegate.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static BalanceStruct::Type gsPowerBalances[] = {
2424
};
2525

2626
// assumes it'll be the only delegate for it's lifetime.
27-
struct EPrefDelegate : public EnergyPreferenceDelegate
27+
struct EPrefDelegate : public Delegate
2828
{
2929
EPrefDelegate();
3030
virtual ~EPrefDelegate();
@@ -37,16 +37,16 @@ struct EPrefDelegate : public EnergyPreferenceDelegate
3737
size_t GetNumLowPowerModes(chip::EndpointId aEndpoint) override;
3838
};
3939

40-
EPrefDelegate::EPrefDelegate() : EnergyPreferenceDelegate()
40+
EPrefDelegate::EPrefDelegate() : Delegate()
4141
{
42-
VerifyOrDie(GetMatterEnergyPreferencesDelegate() == nullptr);
43-
SetMatterEnergyPreferencesDelegate(this);
42+
VerifyOrDie(GetDelegate() == nullptr);
43+
SetDelegate(this);
4444
}
4545

4646
EPrefDelegate::~EPrefDelegate()
4747
{
48-
VerifyOrDie(GetMatterEnergyPreferencesDelegate() == this);
49-
SetMatterEnergyPreferencesDelegate(nullptr);
48+
VerifyOrDie(GetDelegate() == this);
49+
SetDelegate(nullptr);
5050
}
5151

5252
size_t EPrefDelegate::GetNumEnergyBalances(chip::EndpointId aEndpoint)

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

+17-11
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717

1818
#include "energy-preference-server.h"
1919

20-
#include <app/util/af.h>
21-
2220
#include <app/util/attribute-storage.h>
2321

2422
#include <app-common/zap-generated/attributes/Accessors.h>
2523
#include <app-common/zap-generated/callback.h>
2624
#include <app-common/zap-generated/cluster-objects.h>
2725
#include <app-common/zap-generated/ids/Attributes.h>
28-
#include <app/CommandHandler.h>
2926
#include <app/ConcreteAttributePath.h>
3027
#include <app/ConcreteCommandPath.h>
3128
#include <app/util/error-mapping.h>
@@ -52,7 +49,7 @@ class EnergyPrefAttrAccess : public AttributeAccessInterface
5249
};
5350

5451
EnergyPrefAttrAccess gEnergyPrefAttrAccess;
55-
EnergyPreferenceDelegate * gsDelegate = nullptr;
52+
Delegate * gsDelegate = nullptr;
5653

5754
CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
5855
{
@@ -157,22 +154,27 @@ CHIP_ERROR EnergyPrefAttrAccess::Write(const ConcreteDataAttributePath & aPath,
157154

158155
} // anonymous namespace
159156

160-
void SetMatterEnergyPreferencesDelegate(EnergyPreferenceDelegate * aDelegate)
157+
namespace chip::app::Clusters::EnergyPreference
158+
{
159+
160+
void SetDelegate(Delegate * aDelegate)
161161
{
162162
gsDelegate = aDelegate;
163163
}
164164

165-
EnergyPreferenceDelegate * GetMatterEnergyPreferencesDelegate()
165+
Delegate * GetDelegate()
166166
{
167167
return gsDelegate;
168168
}
169169

170+
} // Set matter energy preferences delegate
171+
170172
Protocols::InteractionModel::Status
171173
MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const app::ConcreteAttributePath & attributePath,
172174
EmberAfAttributeType attributeType, uint16_t size, uint8_t * value)
173175
{
174176
EndpointId endpoint = attributePath.mEndpointId;
175-
EnergyPreferenceDelegate * delegate = GetMatterEnergyPreferencesDelegate();
177+
Delegate * delegate = GetDelegate();
176178
uint32_t ourFeatureMap;
177179
bool balanceSupported = (FeatureMap::Get(attributePath.mEndpointId, &ourFeatureMap) == EMBER_ZCL_STATUS_SUCCESS) &&
178180
((ourFeatureMap & to_underlying(Feature::kEnergyBalance)) != 0);
@@ -185,27 +187,31 @@ MatterEnergyPreferenceClusterServerPreAttributeChangedCallback(const app::Concre
185187
{
186188
case CurrentEnergyBalance::Id: {
187189
if (balanceSupported == false)
190+
{
188191
return imcode::UnsupportedAttribute;
192+
}
189193

190-
uint8_t index = chip::Encoding::Get8(value);
194+
uint8_t index = Encoding::Get8(value);
191195
size_t arraySize = delegate->GetNumEnergyBalances(endpoint);
192196
if (index >= arraySize)
193197
{
194-
return imcode::InvalidValue;
198+
return imcode::ConstraintError;
195199
}
196200

197201
return imcode::Success;
198202
}
199203

200204
case CurrentLowPowerModeSensitivity::Id: {
201205
if (lowPowerSupported == false)
206+
{
202207
return imcode::UnsupportedAttribute;
208+
}
203209

204-
uint8_t index = chip::Encoding::Get8(value);
210+
uint8_t index = Encoding::Get8(value);
205211
size_t arraySize = delegate->GetNumLowPowerModes(endpoint);
206212
if (index >= arraySize)
207213
{
208-
return imcode::InvalidValue;
214+
return imcode::ConstraintError;
209215
}
210216

211217
return imcode::Success;

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

+17-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,25 @@
2424
#include <app/util/basic-types.h>
2525
#include <lib/core/CHIPError.h>
2626

27-
struct EnergyPreferenceDelegate
27+
namespace chip::app::Clusters::EnergyPreference
2828
{
29-
virtual ~EnergyPreferenceDelegate() {}
3029

30+
struct Delegate
31+
{
32+
virtual ~Delegate() {}
33+
34+
// Gives a reference to the energy balance struct at aIndex
35+
// Balance struct should exist for the life time of the matter server
3136
virtual CHIP_ERROR GetEnergyBalanceAtIndex(chip::EndpointId aEndpoint, size_t aIndex,
3237
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & balance) = 0;
38+
39+
// Gives a reference to the at aIndex
3340
virtual CHIP_ERROR GetEnergyPriorityAtIndex(chip::EndpointId aEndpoint, size_t aIndex,
3441
chip::app::Clusters::EnergyPreference::EnergyPriorityEnum & priority) = 0;
42+
43+
44+
// Gives a reference to the low power mode sensitivity balance struct at aIndex
45+
// Balance struct should exist for the life time of the matter server
3546
virtual CHIP_ERROR
3647
GetLowPowerModeSensitivityAtIndex(chip::EndpointId aEndpoint, size_t aIndex,
3748
chip::app::Clusters::EnergyPreference::Structs::BalanceStruct::Type & balance) = 0;
@@ -40,5 +51,7 @@ struct EnergyPreferenceDelegate
4051
virtual size_t GetNumLowPowerModes(chip::EndpointId aEndpoint) = 0;
4152
};
4253

43-
void SetMatterEnergyPreferencesDelegate(EnergyPreferenceDelegate * aDelegate);
44-
EnergyPreferenceDelegate * GetMatterEnergyPreferencesDelegate();
54+
void SetDelegate(Delegate * aDelegate);
55+
Delegate * GetDelegate();
56+
57+
} // namespace chip::app::Clusters::EnergyPreference

src/app/common/templates/config-data.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,6 @@ ClustersWithPreAttributeChangeFunctions:
8282
- Mode Select
8383
- Fan Control
8484
- Thermostat
85+
- Energy Preference
8586
- Laundry Washer Controls
8687
- Laundry Dryer Controls

0 commit comments

Comments
 (0)