Skip to content

Commit

Permalink
Patch tests for atomic write of presets
Browse files Browse the repository at this point in the history
  • Loading branch information
hasty committed Aug 2, 2024
1 parent f0b8e7d commit be7ca99
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 95 deletions.
42 changes: 4 additions & 38 deletions examples/thermostat/linux/thermostat-delegate-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,6 @@ using namespace chip::app::Clusters::Thermostat::Structs;

ThermostatDelegate ThermostatDelegate::sInstance;

namespace {

/**
* @brief Checks if the presets are matching i.e the presetHandles are the same.
*
* @param[in] preset The preset to check.
* @param[in] presetToMatch The preset to match with.
*
* @return true If the presets match, false otherwise. If both preset handles are null, returns false
*/
bool PresetHandlesExistAndMatch(const PresetStructWithOwnedMembers & preset, const PresetStructWithOwnedMembers & presetToMatch)
{
return !preset.GetPresetHandle().IsNull() && !presetToMatch.GetPresetHandle().IsNull() &&
preset.GetPresetHandle().Value().data_equal(presetToMatch.GetPresetHandle().Value());
}

} // anonymous namespace

ThermostatDelegate::ThermostatDelegate()
{
mNumberOfPresets = kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType;
Expand Down Expand Up @@ -207,30 +189,14 @@ CHIP_ERROR ThermostatDelegate::GetPendingPresetAtIndex(size_t index, PresetStruc

CHIP_ERROR ThermostatDelegate::ApplyPendingPresets()
{

// TODO: #34546 - Need to support deletion of presets that are removed from Presets.
mNextFreeIndexInPresetsList = 0;
for (uint8_t indexInPendingPresets = 0; indexInPendingPresets < mNextFreeIndexInPendingPresetsList; indexInPendingPresets++)
{
const PresetStructWithOwnedMembers & pendingPreset = mPendingPresets[indexInPendingPresets];
mPresets[mNextFreeIndexInPresetsList] = pendingPreset;
mNextFreeIndexInPresetsList++;
ChipLogError(Zcl, "applied pending preset again");

bool found = false;
for (uint8_t indexInPresets = 0; indexInPresets < mNextFreeIndexInPresetsList; indexInPresets++)
{
if (PresetHandlesExistAndMatch(mPresets[indexInPresets], pendingPreset))
{
found = true;

// Replace the preset with the pending preset
mPresets[indexInPresets] = pendingPreset;
}
}

// If pending preset was not found in the Presets list, append to the Presets list.
if (!found)
{
mPresets[mNextFreeIndexInPresetsList] = pendingPreset;
mNextFreeIndexInPresetsList++;
}
}
return CHIP_NO_ERROR;
}
Expand Down
8 changes: 6 additions & 2 deletions src/app/clusters/thermostat-server/thermostat-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ CHIP_ERROR ThermostatAttrAccess::Write(const ConcreteDataAttributePath & aPath,
// and add to the pending presets list.
if (!aPath.IsListOperation() || aPath.mListOp == ConcreteDataAttributePath::ListOperation::ReplaceAll)
{
ChipLogError(Zcl, "Replace all!");
// Clear the pending presets list
delegate->ClearPendingPresetList();

Expand All @@ -886,6 +887,7 @@ CHIP_ERROR ThermostatAttrAccess::Write(const ConcreteDataAttributePath & aPath,
// If the list operation is AppendItem, call the delegate to append the item to the list of pending presets.
if (aPath.mListOp == ConcreteDataAttributePath::ListOperation::AppendItem)
{
ChipLogError(Zcl, "Appending again!");
PresetStruct::Type preset;
ReturnErrorOnFailure(aDecoder.Decode(preset));
if (IsValidPresetEntry(preset))
Expand Down Expand Up @@ -1571,12 +1573,14 @@ imcode commitPresets(Delegate * delegate, EndpointId endpoint)
{
return imcode::InvalidInState;
}
ChipLogError(Zcl, "committed presets");
return imcode::Success;
}

void handleAtomicCommit(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::AtomicRequest::DecodableType & commandData)
{
ChipLogError(Zcl, "handleAtomicCommit");
if (!validAtomicAttributes(commandData, true))
{
commandObj->AddStatus(commandPath, imcode::InvalidCommand);
Expand Down Expand Up @@ -1711,13 +1715,13 @@ bool emberAfThermostatClusterSetpointRaiseLowerCallback(app::CommandHandler * co
{
DesiredCoolingSetpoint = static_cast<int16_t>(CoolingSetpoint + amount * 10);
CoolLimit = static_cast<int16_t>(DesiredCoolingSetpoint -
EnforceCoolingSetpointLimits(DesiredCoolingSetpoint, aEndpointId));
EnforceCoolingSetpointLimits(DesiredCoolingSetpoint, aEndpointId));
{
if (OccupiedHeatingSetpoint::Get(aEndpointId, &HeatingSetpoint) == imcode::Success)
{
DesiredHeatingSetpoint = static_cast<int16_t>(HeatingSetpoint + amount * 10);
HeatLimit = static_cast<int16_t>(DesiredHeatingSetpoint -
EnforceHeatingSetpointLimits(DesiredHeatingSetpoint, aEndpointId));
EnforceHeatingSetpointLimits(DesiredHeatingSetpoint, aEndpointId));
{
if (CoolLimit != 0 || HeatLimit != 0)
{
Expand Down
6 changes: 1 addition & 5 deletions src/app/tests/suites/certification/ci-pics-values
Original file line number Diff line number Diff line change
Expand Up @@ -2000,8 +2000,6 @@ TSTAT.S.C03.Rsp=0
TSTAT.S.C04.Rsp=0
TSTAT.S.C06.Rsp=1
TSTAT.S.C07.Rsp=1
TSTAT.S.C08.Rsp=1
TSTAT.S.C09.Rsp=1

# Client
TSTAT.C=0
Expand All @@ -2018,12 +2016,10 @@ TSTAT.S.C00.Tx=0
TSTAT.S.C01.Tx=0
TSTAT.C.C06.Tx=1
TSTAT.C.C07.Tx=1
TSTAT.C.C08.Tx=1
TSTAT.C.C09.Tx=1

# Client Commands
TSTAT.C.C00.Tx=1
TSTAT.C.C04.Tx=0
TSTAT.C.C04.Tx=1

# Access Control cluster
ACL.S=1
Expand Down
4 changes: 2 additions & 2 deletions src/controller/python/chip/clusters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
EcosystemInformation, ElectricalEnergyMeasurement, ElectricalMeasurement, ElectricalPowerMeasurement,
EnergyEvse, EnergyEvseMode, EnergyPreference, EthernetNetworkDiagnostics, FanControl, FaultInjection,
FixedLabel, FlowMeasurement, FormaldehydeConcentrationMeasurement, GeneralCommissioning, GeneralDiagnostics,
GroupKeyManagement, Groups, HepaFilterMonitoring, IcdManagement, Identify, IlluminanceMeasurement,
Globals, GroupKeyManagement, Groups, HepaFilterMonitoring, IcdManagement, Identify, IlluminanceMeasurement,
KeypadInput, LaundryDryerControls, LaundryWasherControls, LaundryWasherMode, LevelControl,
LocalizationConfiguration, LowPower, MediaInput, MediaPlayback, MicrowaveOvenControl, MicrowaveOvenMode,
ModeSelect, NetworkCommissioning, NitrogenDioxideConcentrationMeasurement, OccupancySensing, OnOff,
Expand All @@ -56,7 +56,7 @@
ContentControl, ContentLauncher, DemandResponseLoadControl, Descriptor, DeviceEnergyManagementMode, DeviceEnergyManagement, DeviceEnergyManagementMode, DiagnosticLogs, DishwasherAlarm, DishwasherMode,
DoorLock, EcosystemInformation, ElectricalEnergyMeasurement, ElectricalMeasurement, ElectricalPowerMeasurement, EnergyEvse, EnergyEvseMode, EnergyPreference,
EthernetNetworkDiagnostics, FanControl, FaultInjection, FixedLabel, FlowMeasurement,
FormaldehydeConcentrationMeasurement, GeneralCommissioning, GeneralDiagnostics, GroupKeyManagement, Groups,
FormaldehydeConcentrationMeasurement, GeneralCommissioning, GeneralDiagnostics, Globals, GroupKeyManagement, Groups,
HepaFilterMonitoring, IcdManagement, Identify, IlluminanceMeasurement, KeypadInput, LaundryDryerControls,
LaundryWasherControls, LaundryWasherMode, LevelControl, LocalizationConfiguration, LowPower, MediaInput, MediaPlayback, MicrowaveOvenControl,
MicrowaveOvenMode, ModeSelect, NetworkCommissioning, NitrogenDioxideConcentrationMeasurement,
Expand Down
Loading

0 comments on commit be7ca99

Please sign in to comment.