From 7335d4dcc6094e4b53734791bea6fe94340e397b Mon Sep 17 00:00:00 2001 From: Sergio Soares Date: Fri, 15 Nov 2024 20:59:18 +0000 Subject: [PATCH 1/2] chef-fan-control: Remove unnecessary checks With the recent circular callback bugfixes done in the cluster code in pull/36515 and pull/36489, we can now safely remove unnecessary checks that prevented the circular callbacks in the app side. --- .../chef/common/chef-fan-control-manager.cpp | 37 ++++--------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/examples/chef/common/chef-fan-control-manager.cpp b/examples/chef/common/chef-fan-control-manager.cpp index 7c2aec389e08a4..fd45339fa92fc8 100644 --- a/examples/chef/common/chef-fan-control-manager.cpp +++ b/examples/chef/common/chef-fan-control-manager.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -35,6 +36,7 @@ using namespace chip::app::DataModel; using namespace chip::app::Clusters; using namespace chip::app::Clusters::FanControl; using namespace chip::app::Clusters::FanControl::Attributes; +using namespace std; using Protocols::InteractionModel::Status; namespace { @@ -207,11 +209,6 @@ FanControl::FanModeEnum ChefFanControlManager::SpeedToFanMode(uint8_t speed) void ChefFanControlManager::SetPercentCurrent(uint8_t aNewPercentCurrent) { - if (aNewPercentCurrent == mPercentCurrent) - { - return; - } - ChipLogDetail(NotSpecified, "ChefFanControlManager::SetPercentCurrent: %d", aNewPercentCurrent); mPercentCurrent = aNewPercentCurrent; Status status = FanControl::Attributes::PercentCurrent::Set(mEndpoint, mPercentCurrent); @@ -224,12 +221,6 @@ void ChefFanControlManager::SetPercentCurrent(uint8_t aNewPercentCurrent) void ChefFanControlManager::SetSpeedCurrent(uint8_t aNewSpeedCurrent) { - if (aNewSpeedCurrent == mSpeedCurrent) - { - return; - } - - ChipLogDetail(NotSpecified, "ChefFanControlManager::SetSpeedCurrent: %d", aNewSpeedCurrent); mSpeedCurrent = aNewSpeedCurrent; Status status = FanControl::Attributes::SpeedCurrent::Set(mEndpoint, aNewSpeedCurrent); if (status != Status::Success) @@ -245,11 +236,8 @@ void ChefFanControlManager::FanModeWriteCallback(FanControl::FanModeEnum aNewFan switch (aNewFanMode) { case FanControl::FanModeEnum::kOff: { - if (mSpeedCurrent != 0) - { - DataModel::Nullable speedSetting(0); - SetSpeedSetting(speedSetting); - } + DataModel::Nullable speedSetting(0); + SetSpeedSetting(speedSetting); break; } case FanControl::FanModeEnum::kLow: { @@ -291,20 +279,11 @@ void ChefFanControlManager::FanModeWriteCallback(FanControl::FanModeEnum aNewFan void ChefFanControlManager::SetSpeedSetting(DataModel::Nullable aNewSpeedSetting) { - if (aNewSpeedSetting.IsNull()) - { - ChipLogError(NotSpecified, "ChefFanControlManager::SetSpeedSetting: null value is invalid"); - return; - } - - if (aNewSpeedSetting.Value() != mSpeedCurrent) + Status status = FanControl::Attributes::SpeedSetting::Set(mEndpoint, aNewSpeedSetting); + if (status != Status::Success) { - Status status = FanControl::Attributes::SpeedSetting::Set(mEndpoint, aNewSpeedSetting); - if (status != Status::Success) - { - ChipLogError(NotSpecified, "ChefFanControlManager::SetSpeedSetting: failed to set SpeedSetting attribute: %d", - to_underlying(status)); - } + ChipLogError(NotSpecified, "ChefFanControlManager::SetSpeedSetting: failed to set SpeedSetting attribute: %d", + to_underlying(status)); } } From 757cbdd05233d88c2d2dc2986a3de003a4d1357f Mon Sep 17 00:00:00 2001 From: Sergio Soares Date: Fri, 15 Nov 2024 21:04:12 +0000 Subject: [PATCH 2/2] remove unused includes/imports. --- examples/chef/common/chef-fan-control-manager.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/chef/common/chef-fan-control-manager.cpp b/examples/chef/common/chef-fan-control-manager.cpp index fd45339fa92fc8..42555e8052bea0 100644 --- a/examples/chef/common/chef-fan-control-manager.cpp +++ b/examples/chef/common/chef-fan-control-manager.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include @@ -36,7 +35,6 @@ using namespace chip::app::DataModel; using namespace chip::app::Clusters; using namespace chip::app::Clusters::FanControl; using namespace chip::app::Clusters::FanControl::Attributes; -using namespace std; using Protocols::InteractionModel::Status; namespace {