diff --git a/src/app/clusters/fan-control-server/fan-control-server.cpp b/src/app/clusters/fan-control-server/fan-control-server.cpp index 7ece1a1b575a24..2c30c9c6cdfa70 100644 --- a/src/app/clusters/fan-control-server/fan-control-server.cpp +++ b/src/app/clusters/fan-control-server/fan-control-server.cpp @@ -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) { @@ -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); @@ -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)