diff --git a/src/app/clusters/thermostat-server/thermostat-server.cpp b/src/app/clusters/thermostat-server/thermostat-server.cpp index afdb1b12afe763..c13a2175b43899 100644 --- a/src/app/clusters/thermostat-server/thermostat-server.cpp +++ b/src/app/clusters/thermostat-server/thermostat-server.cpp @@ -321,9 +321,10 @@ bool IsPresetHandlePresentInPresets(Delegate * delegate, const ByteSpan & preset } /** - * @brief Returns the length of the list of presets if the pending presets were to be applied. The calculation is done by - * adding the number of presets in Presets attribute list to the number of pending presets in the pending - * presets list and subtracting the number of duplicate presets. This is called before changes are actually applied. + * @brief Returns the length of the list of presets if the pending presets were to be applied. The size of the pending presets list + * calculated, after all the constraint checks are done, is the new size of the updated Presets attribute since the pending + * preset list is expected to have all existing presets with or without edits plus new presets. + * This is called before changes are actually applied. * * @param[in] delegate The delegate to use. * @@ -331,36 +332,10 @@ bool IsPresetHandlePresentInPresets(Delegate * delegate, const ByteSpan & preset */ uint8_t CountUpdatedPresetsAfterApplyingPendingPresets(Delegate * delegate) { - uint8_t numberOfPresets = 0; - uint8_t numberOfMatches = 0; uint8_t numberOfPendingPresets = 0; VerifyOrReturnValue(delegate != nullptr, 0); - for (uint8_t i = 0; true; i++) - { - PresetStructWithOwnedMembers preset; - CHIP_ERROR err = delegate->GetPresetAtIndex(i, preset); - - if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) - { - break; - } - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, "GetUpdatedPresetsCount: GetPresetAtIndex failed with error %" CHIP_ERROR_FORMAT, err.Format()); - return 0; - } - numberOfPresets++; - - bool found = MatchingPendingPresetExists(delegate, preset); - - if (found) - { - numberOfMatches++; - } - } - for (uint8_t i = 0; true; i++) { PresetStructWithOwnedMembers pendingPreset; @@ -372,16 +347,14 @@ uint8_t CountUpdatedPresetsAfterApplyingPendingPresets(Delegate * delegate) } if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "GetUpdatedPresetsCount: GetPendingPresetAtIndex failed with error %" CHIP_ERROR_FORMAT, + ChipLogError(Zcl, "CountUpdatedPresetsAfterApplyingPendingPresets: GetPendingPresetAtIndex failed with error %" CHIP_ERROR_FORMAT, err.Format()); return 0; } numberOfPendingPresets++; } - // TODO: #34546 - Need to support deletion of presets that are removed from Presets. - // This API needs to modify its logic for the deletion case. - return static_cast(numberOfPresets + numberOfPendingPresets - numberOfMatches); + return static_cast(numberOfPendingPresets); } /**