@@ -321,46 +321,21 @@ bool IsPresetHandlePresentInPresets(Delegate * delegate, const ByteSpan & preset
321
321
}
322
322
323
323
/* *
324
- * @brief Returns the length of the list of presets if the pending presets were to be applied. The calculation is done by
325
- * adding the number of presets in Presets attribute list to the number of pending presets in the pending
326
- * presets list and subtracting the number of duplicate presets. This is called before changes are actually applied.
324
+ * @brief Returns the length of the list of presets if the pending presets were to be applied. The size of the pending presets list
325
+ * calculated, after all the constraint checks are done, is the new size of the updated Presets attribute since the pending
326
+ * preset list is expected to have all existing presets with or without edits plus new presets.
327
+ * This is called before changes are actually applied.
327
328
*
328
329
* @param[in] delegate The delegate to use.
329
330
*
330
331
* @return count of the updated Presets attribute if the pending presets were applied to it. Return 0 for error cases.
331
332
*/
332
- uint8_t CountUpdatedPresetsAfterApplyingPendingPresets (Delegate * delegate)
333
+ uint8_t CountNumberOfPendingPresets (Delegate * delegate)
333
334
{
334
- uint8_t numberOfPresets = 0 ;
335
- uint8_t numberOfMatches = 0 ;
336
335
uint8_t numberOfPendingPresets = 0 ;
337
336
338
337
VerifyOrReturnValue (delegate != nullptr , 0 );
339
338
340
- for (uint8_t i = 0 ; true ; i++)
341
- {
342
- PresetStructWithOwnedMembers preset;
343
- CHIP_ERROR err = delegate->GetPresetAtIndex (i, preset);
344
-
345
- if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
346
- {
347
- break ;
348
- }
349
- if (err != CHIP_NO_ERROR)
350
- {
351
- ChipLogError (Zcl, " GetUpdatedPresetsCount: GetPresetAtIndex failed with error %" CHIP_ERROR_FORMAT, err.Format ());
352
- return 0 ;
353
- }
354
- numberOfPresets++;
355
-
356
- bool found = MatchingPendingPresetExists (delegate, preset);
357
-
358
- if (found)
359
- {
360
- numberOfMatches++;
361
- }
362
- }
363
-
364
339
for (uint8_t i = 0 ; true ; i++)
365
340
{
366
341
PresetStructWithOwnedMembers pendingPreset;
@@ -372,16 +347,14 @@ uint8_t CountUpdatedPresetsAfterApplyingPendingPresets(Delegate * delegate)
372
347
}
373
348
if (err != CHIP_NO_ERROR)
374
349
{
375
- ChipLogError (Zcl, " GetUpdatedPresetsCount : GetPendingPresetAtIndex failed with error %" CHIP_ERROR_FORMAT,
350
+ ChipLogError (Zcl, " CountNumberOfPendingPresets : GetPendingPresetAtIndex failed with error %" CHIP_ERROR_FORMAT,
376
351
err.Format ());
377
352
return 0 ;
378
353
}
379
354
numberOfPendingPresets++;
380
355
}
381
356
382
- // TODO: #34546 - Need to support deletion of presets that are removed from Presets.
383
- // This API needs to modify its logic for the deletion case.
384
- return static_cast <uint8_t >(numberOfPresets + numberOfPendingPresets - numberOfMatches);
357
+ return numberOfPendingPresets;
385
358
}
386
359
387
360
/* *
@@ -1538,7 +1511,7 @@ imcode commitPresets(Delegate * delegate, EndpointId endpoint)
1538
1511
}
1539
1512
}
1540
1513
1541
- uint8_t totalCount = CountUpdatedPresetsAfterApplyingPendingPresets (delegate);
1514
+ uint8_t totalCount = CountNumberOfPendingPresets (delegate);
1542
1515
1543
1516
uint8_t numberOfPresetsSupported = delegate->GetNumberOfPresets ();
1544
1517
0 commit comments