Skip to content

Commit 0f89586

Browse files
Update MeterID attrs if it changed only
1 parent ea9d2ee commit 0f89586

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

examples/all-clusters-app/all-clusters-common/include/meter-identification-delegate.h

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class MeterIdentificationDelegate : public MeterIdentification::Delegate
5252
CHIP_ERROR SetPowerThresholdSource(DataModel::Nullable<PowerThresholdSourceEnum>);
5353

5454
private:
55+
56+
static bool NullableCharSpanCompare(DataModel::Nullable<CharSpan> a, DataModel::Nullable<CharSpan> b);
57+
5558
// Attribute storage
5659
DataModel::Nullable<MeterTypeEnum> mMeterType;
5760
DataModel::Nullable<CharSpan> mUtilityName;

examples/all-clusters-app/all-clusters-common/src/meter-identification-delegate.cpp

+39-23
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,23 @@ CHIP_ERROR MeterIdentificationDelegate::LoadJson(Json::Value & root)
159159

160160
CHIP_ERROR MeterIdentificationDelegate::SetMeterType(DataModel::Nullable<MeterTypeEnum> newValue)
161161
{
162-
// DataModel::Nullable<MeterTypeEnum> oldValue = mMeterType;
162+
DataModel::Nullable<MeterTypeEnum> oldValue = mMeterType;
163163

164164
mMeterType = newValue;
165-
// if (oldValue != newValue)
166-
//{
165+
if (oldValue != newValue)
166+
{
167167
MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, MeterType::Id);
168-
// }
168+
}
169169

170170
return CHIP_NO_ERROR;
171171
}
172172

173173
CHIP_ERROR MeterIdentificationDelegate::SetUtilityName(DataModel::Nullable<CharSpan> newValue)
174174
{
175-
// CharSpan oldValue = mUtilityName;
175+
if (NullableCharSpanCompare(mUtilityName, newValue))
176+
{
177+
return CHIP_NO_ERROR;
178+
}
176179

177180
if (!mUtilityName.IsNull())
178181
{
@@ -189,17 +192,17 @@ CHIP_ERROR MeterIdentificationDelegate::SetUtilityName(DataModel::Nullable<CharS
189192
mUtilityName = MakeNullable(CharSpan::fromCharString(str));
190193
}
191194

192-
// if (!oldValue.data_equal(newValue))
193-
//{
194-
MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, UtilityName::Id);
195-
// }
195+
MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, UtilityName::Id);
196196

197197
return CHIP_NO_ERROR;
198198
}
199199

200200
CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery(DataModel::Nullable<CharSpan> newValue)
201201
{
202-
// CharSpan oldValue = mPointOfDelivery;
202+
if (NullableCharSpanCompare(mPointOfDelivery, newValue))
203+
{
204+
return CHIP_NO_ERROR;
205+
}
203206

204207
if (!mPointOfDelivery.IsNull())
205208
{
@@ -216,40 +219,53 @@ CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery(DataModel::Nullable<C
216219
mPointOfDelivery = MakeNullable(CharSpan::fromCharString(str));
217220
}
218221

219-
// if (!oldValue.data_equal(newValue))
220-
//{
221-
MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, PointOfDelivery::Id);
222-
// }
222+
MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, PointOfDelivery::Id);
223223

224224
return CHIP_NO_ERROR;
225225
}
226226

227227
CHIP_ERROR MeterIdentificationDelegate::SetPowerThreshold(DataModel::Nullable<int64_t> newValue)
228228
{
229-
// DataModel::Nullable<uint64_t> oldValue = mPowerThreshold;
229+
DataModel::Nullable<int64_t> oldValue = mPowerThreshold;
230230

231231
mPowerThreshold = newValue;
232-
// if (oldValue != newValue)
233-
//{
234-
MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, PowerThreshold::Id);
235-
// }
232+
if (oldValue != newValue)
233+
{
234+
MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, PowerThreshold::Id);
235+
}
236236

237237
return CHIP_NO_ERROR;
238238
}
239239

240240
CHIP_ERROR MeterIdentificationDelegate::SetPowerThresholdSource(DataModel::Nullable<PowerThresholdSourceEnum> newValue)
241241
{
242-
// DataModel::Nullable<PowerThresholdSourceEnum> oldValue = mPowerThresholdSource;
242+
DataModel::Nullable<PowerThresholdSourceEnum> oldValue = mPowerThresholdSource;
243243

244244
mPowerThresholdSource = newValue;
245-
// if (oldValue != newValue)
246-
//{
245+
if (oldValue != newValue)
246+
{
247247
MatterReportingAttributeChangeCallback(mEndpointId, MeterIdentification::Id, PowerThresholdSource::Id);
248-
// }
248+
}
249249

250250
return CHIP_NO_ERROR;
251251
}
252252

253+
bool MeterIdentificationDelegate::NullableCharSpanCompare(DataModel::Nullable<CharSpan> a,
254+
DataModel::Nullable<CharSpan> b)
255+
{
256+
if (a.IsNull() && b.IsNull())
257+
{
258+
return true;
259+
}
260+
261+
if (!a.IsNull() && !b.IsNull())
262+
{
263+
return a.Value().data_equal(b.Value());
264+
}
265+
266+
return false;
267+
}
268+
253269
static std::unique_ptr<MeterIdentificationDelegate> gMIDelegate;
254270
static std::unique_ptr<MeterIdentificationInstance> gMIInstance;
255271
static BitMask<Feature> gMIFeature = BitMask<Feature, uint32_t>(Feature::kPowerThreshold);

0 commit comments

Comments
 (0)