Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the constraint check for number of presets not to exceed the num… #35167

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/app/clusters/thermostat-server/thermostat-server-presets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,28 @@ CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Thermostat::Delegate * dele
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}

// Before adding this preset to the pending presets, if the expected length of the pending presets' list
// exceeds the total number of presets supported, return RESOURCE_EXHAUSTED. Note that the preset has not been appended yet.

// Increment number of pending presets by 1 to account for this preset.
uint8_t totalExpectedCount = CountNumberOfPendingPresets(delegate) + 1;

uint8_t numberOfPresetsSupported = delegate->GetNumberOfPresets();

if (numberOfPresetsSupported == 0)
{
ChipLogError(Zcl, "AppendPendingPreset: Failed to get NumberOfPresets");
return CHIP_IM_GLOBAL_STATUS(InvalidInState);
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
}

if (numberOfPresetsSupported > 0 && totalExpectedCount > numberOfPresetsSupported)
nivi-apple marked this conversation as resolved.
Show resolved Hide resolved
{
return CHIP_IM_GLOBAL_STATUS(ResourceExhausted);
}

// TODO #34556 : Check if the number of presets for each presetScenario exceeds the max number of presets supported for that
// scenario. We plan to support only one preset for each presetScenario for our use cases so defer this for re-evaluation.

return delegate->AppendToPendingPresetList(preset);
}

Expand Down Expand Up @@ -504,25 +526,6 @@ Status ThermostatAttrAccess::PrecommitPresets(EndpointId endpoint)
}
}

uint8_t totalCount = CountNumberOfPendingPresets(delegate);

uint8_t numberOfPresetsSupported = delegate->GetNumberOfPresets();

if (numberOfPresetsSupported == 0)
{
ChipLogError(Zcl, "emberAfThermostatClusterCommitPresetsSchedulesRequestCallback: Failed to get NumberOfPresets");
return Status::InvalidInState;
}

// If the expected length of the presets attribute with the applied changes exceeds the total number of presets supported,
// return RESOURCE_EXHAUSTED. Note that the changes are not yet applied.
if (numberOfPresetsSupported > 0 && totalCount > numberOfPresetsSupported)
{
return Status::ResourceExhausted;
}

// TODO: Check if the number of presets for each presetScenario exceeds the max number of presets supported for that
// scenario. We plan to support only one preset for each presetScenario for our use cases so defer this for re-evaluation.
return Status::Success;
}

Expand Down
Loading