Skip to content

Commit a83f1fb

Browse files
lboueCopilot
andcommitted
refactor(thermostat): centralize ActivePresetHandle subscription reporting
Co-authored-by: Copilot <copilot@github.com>
1 parent b73e49f commit a83f1fb

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

examples/thermostat/thermostat-common/src/thermostat-delegate-impl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ CHIP_ERROR ThermostatDelegate::SetActivePresetHandle(const DataModel::Nullable<B
168168
mActivePresetHandleDataSize = 0;
169169
ChipLogDetail(NotSpecified, "Clear ActivePresetHandle");
170170
}
171+
172+
// Centralize ActivePresetHandle reporting here so all update paths
173+
// calling SetActivePresetHandle trigger a consistent subscription report.
174+
MatterReportingAttributeChangeCallback(mEndpointId, Thermostat::Id, Attributes::ActivePresetHandle::Id);
175+
171176
return CHIP_NO_ERROR;
172177
}
173178

@@ -449,7 +454,6 @@ CHIP_ERROR ThermostatDelegate::ReEvaluateCurrentSuggestion()
449454
// ActivePresetHandle. Otherwise set the ActivePresetHandle to the preset handle in the suggestion and set
450455
// ThermostatSuggestionNotFollowingReason to null.
451456
TEMPORARY_RETURN_IGNORED SetActivePresetHandle(currentThermostatSuggestion.GetPresetHandle());
452-
MatterReportingAttributeChangeCallback(mEndpointId, Thermostat::Id, Attributes::ActivePresetHandle::Id);
453457
TEMPORARY_RETURN_IGNORED SetThermostatSuggestionNotFollowingReason(DataModel::NullNullable);
454458

455459
// Start a timer from the timestamp in currentMatterEpochTimestamp to the timestamp in the expiration time.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ Status ThermostatAttrAccess::SetActivePreset(EndpointId endpoint, DataModel::Nul
309309
return Status::InvalidCommand;
310310
}
311311

312+
// Delegate centralizes ActivePresetHandle subscription reporting to ensure
313+
// all update paths (command and suggestion-driven) emit reports consistently.
312314
CHIP_ERROR err = delegate->SetActivePresetHandle(presetHandle);
313315

314316
if (err != CHIP_NO_ERROR)
@@ -317,10 +319,6 @@ Status ThermostatAttrAccess::SetActivePreset(EndpointId endpoint, DataModel::Nul
317319
return StatusIB(err).mStatus;
318320
}
319321

320-
// Notify subscribers that ActivePresetHandle has changed so that they
321-
// receive a subscription report with the new value.
322-
MatterReportingAttributeChangeCallback(endpoint, Thermostat::Id, ActivePresetHandle::Id);
323-
324322
return Status::Success;
325323
}
326324

0 commit comments

Comments
 (0)