Skip to content

Commit acba7f8

Browse files
Move the constraint check for number of presets not to exceed the num… (#35167)
* Move the constraint check for number of presets not to exceed the number of presets supported from the atomic write commit command handling to the write request * Minor fix * Do not check if totalExpectedCount > 0 since its an unsigned integer - Also no need to check if numberOfPresetsSupported is 0. * Update src/app/clusters/thermostat-server/thermostat-server-presets.cpp * Update src/app/clusters/thermostat-server/thermostat-server-presets.cpp --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent a296b66 commit acba7f8

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

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

+14-19
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,20 @@ CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Thermostat::Delegate * dele
402402
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
403403
}
404404

405+
// Before adding this preset to the pending presets, if the expected length of the pending presets' list
406+
// exceeds the total number of presets supported, return RESOURCE_EXHAUSTED. Note that the preset has not been appended yet.
407+
408+
uint8_t numberOfPendingPresets = CountNumberOfPendingPresets(delegate);
409+
410+
// We will be adding one more preset, so reject if the length is already at max.
411+
if (numberOfPendingPresets >= delegate->GetNumberOfPresets())
412+
{
413+
return CHIP_IM_GLOBAL_STATUS(ResourceExhausted);
414+
}
415+
416+
// TODO #34556 : Check if the number of presets for each presetScenario exceeds the max number of presets supported for that
417+
// scenario. We plan to support only one preset for each presetScenario for our use cases so defer this for re-evaluation.
418+
405419
return delegate->AppendToPendingPresetList(preset);
406420
}
407421

@@ -504,25 +518,6 @@ Status ThermostatAttrAccess::PrecommitPresets(EndpointId endpoint)
504518
}
505519
}
506520

507-
uint8_t totalCount = CountNumberOfPendingPresets(delegate);
508-
509-
uint8_t numberOfPresetsSupported = delegate->GetNumberOfPresets();
510-
511-
if (numberOfPresetsSupported == 0)
512-
{
513-
ChipLogError(Zcl, "emberAfThermostatClusterCommitPresetsSchedulesRequestCallback: Failed to get NumberOfPresets");
514-
return Status::InvalidInState;
515-
}
516-
517-
// If the expected length of the presets attribute with the applied changes exceeds the total number of presets supported,
518-
// return RESOURCE_EXHAUSTED. Note that the changes are not yet applied.
519-
if (numberOfPresetsSupported > 0 && totalCount > numberOfPresetsSupported)
520-
{
521-
return Status::ResourceExhausted;
522-
}
523-
524-
// TODO: Check if the number of presets for each presetScenario exceeds the max number of presets supported for that
525-
// scenario. We plan to support only one preset for each presetScenario for our use cases so defer this for re-evaluation.
526521
return Status::Success;
527522
}
528523

0 commit comments

Comments
 (0)