Skip to content

Commit 12a9d1c

Browse files
committed
Fix the CountUpdatedPresetsAfterApplyingPendingPresets utility function to return the size of the pending presets list
1 parent b9c192b commit 12a9d1c

File tree

1 file changed

+6
-33
lines changed

1 file changed

+6
-33
lines changed

src/app/clusters/thermostat-server/thermostat-server.cpp

+6-33
Original file line numberDiff line numberDiff line change
@@ -321,46 +321,21 @@ bool IsPresetHandlePresentInPresets(Delegate * delegate, const ByteSpan & preset
321321
}
322322

323323
/**
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.
327328
*
328329
* @param[in] delegate The delegate to use.
329330
*
330331
* @return count of the updated Presets attribute if the pending presets were applied to it. Return 0 for error cases.
331332
*/
332333
uint8_t CountUpdatedPresetsAfterApplyingPendingPresets(Delegate * delegate)
333334
{
334-
uint8_t numberOfPresets = 0;
335-
uint8_t numberOfMatches = 0;
336335
uint8_t numberOfPendingPresets = 0;
337336

338337
VerifyOrReturnValue(delegate != nullptr, 0);
339338

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-
364339
for (uint8_t i = 0; true; i++)
365340
{
366341
PresetStructWithOwnedMembers pendingPreset;
@@ -372,16 +347,14 @@ uint8_t CountUpdatedPresetsAfterApplyingPendingPresets(Delegate * delegate)
372347
}
373348
if (err != CHIP_NO_ERROR)
374349
{
375-
ChipLogError(Zcl, "GetUpdatedPresetsCount: GetPendingPresetAtIndex failed with error %" CHIP_ERROR_FORMAT,
350+
ChipLogError(Zcl, "CountUpdatedPresetsAfterApplyingPendingPresets: GetPendingPresetAtIndex failed with error %" CHIP_ERROR_FORMAT,
376351
err.Format());
377352
return 0;
378353
}
379354
numberOfPendingPresets++;
380355
}
381356

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 static_cast<uint8_t>(numberOfPendingPresets);
385358
}
386359

387360
/**

0 commit comments

Comments
 (0)