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

fan-control-server: Fix FanMode circular callback issue #36515

Merged
Merged
Changes from all commits
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
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
Loading