Skip to content

Commit

Permalink
fan-control-server: Fix FanMode circular callback issue (#36515)
Browse files Browse the repository at this point in the history
Similar to what was done for Speed and Percent, this PR fixes a bug where
a FanMode could result in a circular callback.

For example, setting the FanMode to kAuto, could trigger this issue.
  • Loading branch information
soares-sergio authored and pull[bot] committed Dec 5, 2024
1 parent a93a2f5 commit 1008888
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/app/clusters/fan-control-server/fan-control-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ bool gWriteFromClusterLogic = false;
// Avoid circular callback calls when adjusting SpeedSetting and PercentSetting together.
ScopedChangeOnly gSpeedWriteInProgress(false);
ScopedChangeOnly gPercentWriteInProgress(false);
ScopedChangeOnly gFanModeWriteInProgress(false);

Status SetFanModeToOff(EndpointId endpointId)
{
Expand Down Expand Up @@ -160,12 +161,16 @@ MatterFanControlClusterServerPreAttributeChangedCallback(const ConcreteAttribute
switch (attributePath.mAttributeId)
{
case FanMode::Id: {
if (gFanModeWriteInProgress)
{
return Status::WriteIgnored;
}
if (*value == to_underlying(FanModeEnum::kOn))
{
FanMode::Set(attributePath.mEndpointId, FanModeEnum::kHigh);
res = Status::WriteIgnored;
return Status::WriteIgnored;
}
else if (*value == to_underlying(FanModeEnum::kSmart))
if (*value == to_underlying(FanModeEnum::kSmart))
{
FanModeSequenceEnum fanModeSequence;
Status status = FanModeSequence::Get(attributePath.mEndpointId, &fanModeSequence);
Expand Down Expand Up @@ -328,6 +333,9 @@ void MatterFanControlClusterServerAttributeChangedCallback(const app::ConcreteAt
Status status = FanMode::Get(attributePath.mEndpointId, &mode);
VerifyOrReturn(Status::Success == status);

// Avoid circular callback calls
ScopedChange FanModeWriteInProgress(gFanModeWriteInProgress, true);

// Setting the FanMode value to Off SHALL set the values of PercentSetting, PercentCurrent,
// SpeedSetting, SpeedCurrent attributes to 0 (zero).
if (mode == FanModeEnum::kOff)
Expand Down

0 comments on commit 1008888

Please sign in to comment.