@@ -159,20 +159,23 @@ CHIP_ERROR MeterIdentificationDelegate::LoadJson(Json::Value & root)
159
159
160
160
CHIP_ERROR MeterIdentificationDelegate::SetMeterType (DataModel::Nullable<MeterTypeEnum> newValue)
161
161
{
162
- // DataModel::Nullable<MeterTypeEnum> oldValue = mMeterType;
162
+ DataModel::Nullable<MeterTypeEnum> oldValue = mMeterType ;
163
163
164
164
mMeterType = newValue;
165
- // if (oldValue != newValue)
166
- // {
165
+ if (oldValue != newValue)
166
+ {
167
167
MatterReportingAttributeChangeCallback (mEndpointId , MeterIdentification::Id, MeterType::Id);
168
- // }
168
+ }
169
169
170
170
return CHIP_NO_ERROR;
171
171
}
172
172
173
173
CHIP_ERROR MeterIdentificationDelegate::SetUtilityName (DataModel::Nullable<CharSpan> newValue)
174
174
{
175
- // CharSpan oldValue = mUtilityName;
175
+ if (NullableCharSpanCompare (mUtilityName , newValue))
176
+ {
177
+ return CHIP_NO_ERROR;
178
+ }
176
179
177
180
if (!mUtilityName .IsNull ())
178
181
{
@@ -189,17 +192,17 @@ CHIP_ERROR MeterIdentificationDelegate::SetUtilityName(DataModel::Nullable<CharS
189
192
mUtilityName = MakeNullable (CharSpan::fromCharString (str));
190
193
}
191
194
192
- // if (!oldValue.data_equal(newValue))
193
- // {
194
- MatterReportingAttributeChangeCallback (mEndpointId , MeterIdentification::Id, UtilityName::Id);
195
- // }
195
+ MatterReportingAttributeChangeCallback (mEndpointId , MeterIdentification::Id, UtilityName::Id);
196
196
197
197
return CHIP_NO_ERROR;
198
198
}
199
199
200
200
CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery (DataModel::Nullable<CharSpan> newValue)
201
201
{
202
- // CharSpan oldValue = mPointOfDelivery;
202
+ if (NullableCharSpanCompare (mPointOfDelivery , newValue))
203
+ {
204
+ return CHIP_NO_ERROR;
205
+ }
203
206
204
207
if (!mPointOfDelivery .IsNull ())
205
208
{
@@ -216,40 +219,53 @@ CHIP_ERROR MeterIdentificationDelegate::SetPointOfDelivery(DataModel::Nullable<C
216
219
mPointOfDelivery = MakeNullable (CharSpan::fromCharString (str));
217
220
}
218
221
219
- // if (!oldValue.data_equal(newValue))
220
- // {
221
- MatterReportingAttributeChangeCallback (mEndpointId , MeterIdentification::Id, PointOfDelivery::Id);
222
- // }
222
+ MatterReportingAttributeChangeCallback (mEndpointId , MeterIdentification::Id, PointOfDelivery::Id);
223
223
224
224
return CHIP_NO_ERROR;
225
225
}
226
226
227
227
CHIP_ERROR MeterIdentificationDelegate::SetPowerThreshold (DataModel::Nullable<int64_t > newValue)
228
228
{
229
- // DataModel::Nullable<uint64_t > oldValue = mPowerThreshold;
229
+ DataModel::Nullable<int64_t > oldValue = mPowerThreshold ;
230
230
231
231
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
+ }
236
236
237
237
return CHIP_NO_ERROR;
238
238
}
239
239
240
240
CHIP_ERROR MeterIdentificationDelegate::SetPowerThresholdSource (DataModel::Nullable<PowerThresholdSourceEnum> newValue)
241
241
{
242
- // DataModel::Nullable<PowerThresholdSourceEnum> oldValue = mPowerThresholdSource;
242
+ DataModel::Nullable<PowerThresholdSourceEnum> oldValue = mPowerThresholdSource ;
243
243
244
244
mPowerThresholdSource = newValue;
245
- // if (oldValue != newValue)
246
- // {
245
+ if (oldValue != newValue)
246
+ {
247
247
MatterReportingAttributeChangeCallback (mEndpointId , MeterIdentification::Id, PowerThresholdSource::Id);
248
- // }
248
+ }
249
249
250
250
return CHIP_NO_ERROR;
251
251
}
252
252
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
+
253
269
static std::unique_ptr<MeterIdentificationDelegate> gMIDelegate ;
254
270
static std::unique_ptr<MeterIdentificationInstance> gMIInstance ;
255
271
static BitMask<Feature> gMIFeature = BitMask<Feature, uint32_t >(Feature::kPowerThreshold );
0 commit comments