diff --git a/src/app/clusters/thermostat-server/thermostat-server-presets.cpp b/src/app/clusters/thermostat-server/thermostat-server-presets.cpp index a880ba236ac224..3de3fcd486a8fe 100644 --- a/src/app/clusters/thermostat-server/thermostat-server-presets.cpp +++ b/src/app/clusters/thermostat-server/thermostat-server-presets.cpp @@ -154,32 +154,34 @@ bool GetMatchingPresetInPresets(Delegate * delegate, const DataModel::NullableGetPresetTypeAtIndex(i, presetType); - if (err != CHIP_NO_ERROR) + if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED) { - // Either we failed to fetch the next preset type, in which case we should error higher, - // or we exhausted the list trying to find the preset type - return 0; + // We exhausted the list trying to find the preset scenario + return CHIP_NO_ERROR; + } + else if (err != CHIP_NO_ERROR) + { + return err; } - if (presetType.presetScenario == presetScenario) { - return presetType.numberOfPresets; + count = presetType.numberOfPresets; + return CHIP_NO_ERROR; } } - return 0; + return CHIP_NO_ERROR; } /** @@ -379,8 +381,13 @@ CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Thermostat::Delegate * dele } } - size_t maximumPresetCount = delegate->GetNumberOfPresets(); - size_t maximumPresetScenarioCount = MaximumPresetScenarioCount(delegate, preset.GetPresetScenario()); + size_t maximumPresetCount = delegate->GetNumberOfPresets(); + + size_t maximumPresetScenarioCount = 0; + if (MaximumPresetScenarioCount(delegate, preset.GetPresetScenario(), maximumPresetScenarioCount) != CHIP_NO_ERROR) + { + return CHIP_IM_GLOBAL_STATUS(InvalidInState); + } if (maximumPresetScenarioCount == 0) {