Skip to content

Commit

Permalink
Move the constraint check for number of presets not to exceed the num…
Browse files Browse the repository at this point in the history
…ber of presets supported from the atomic write commit command handling to the write request
  • Loading branch information
nivi-apple committed Aug 23, 2024
1 parent daa2a57 commit bc1cba0
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/app/clusters/thermostat-server/thermostat-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,26 @@ CHIP_ERROR ThermostatAttrAccess::AppendPendingPreset(Thermostat::Delegate * dele
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}

uint8_t totalCount = CountNumberOfPendingPresets(delegate);

uint8_t numberOfPresetsSupported = delegate->GetNumberOfPresets();

if (numberOfPresetsSupported == 0)
{
ChipLogError(Zcl, "AppendPendingPreset: Failed to get NumberOfPresets");
return CHIP_IM_GLOBAL_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 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 @@ -1517,26 +1537,6 @@ imcode commitPresets(Delegate * delegate, EndpointId endpoint)
}
}

uint8_t totalCount = CountNumberOfPendingPresets(delegate);

uint8_t numberOfPresetsSupported = delegate->GetNumberOfPresets();

if (numberOfPresetsSupported == 0)
{
ChipLogError(Zcl, "emberAfThermostatClusterCommitPresetsSchedulesRequestCallback: Failed to get NumberOfPresets");
return imcode::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 imcode::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.

// Call the delegate API to apply the pending presets to the presets attribute and update it.
err = delegate->ApplyPendingPresets();

Expand Down

0 comments on commit bc1cba0

Please sign in to comment.