diff --git a/src/app/clusters/level-control/level-control.cpp b/src/app/clusters/level-control/level-control.cpp index 824447de3dab05..82aba19ed340e7 100644 --- a/src/app/clusters/level-control/level-control.cpp +++ b/src/app/clusters/level-control/level-control.cpp @@ -1027,20 +1027,6 @@ void emberAfOnOffClusterLevelControlEffectCallback(EndpointId endpoint, bool new return; } - // if the OnOff feature is not supported, the effect on LevelControl is ignored - if (!HasFeature(endpoint, chip::app::Clusters::LevelControl::LevelControlFeature::kOnOff)) - { - emberAfLevelControlClusterPrintln("OnOff feature not supported, ignore LevelControlEffect"); - if (!newValue) - { - // OnOff server expects LevelControl to handle the OnOff attribute change, - // when going to off state. The attribute is set directly rather - // than using setOnOff function to avoid misleading comments in log. - OnOff::Attributes::OnOff::Set(endpoint, OnOff::Commands::Off::Id); - } - return; - } - uint8_t minimumLevelAllowedForTheDevice = state->minLevel; // "Temporarily store CurrentLevel." @@ -1255,7 +1241,7 @@ static bool areStartUpLevelControlServerAttributesNonVolatile(EndpointId endpoin void emberAfPluginLevelControlClusterServerPostInitCallback(EndpointId endpoint) {} -bool HasFeature(chip::EndpointId endpoint, chip::app::Clusters::LevelControl::LevelControlFeature feature) +bool LevelControlHasFeature(EndpointId endpoint, LevelControlFeature feature) { bool success; uint32_t featureMap; diff --git a/src/app/clusters/level-control/level-control.h b/src/app/clusters/level-control/level-control.h index de7ad420f6ba5f..f332b1b5f27d87 100644 --- a/src/app/clusters/level-control/level-control.h +++ b/src/app/clusters/level-control/level-control.h @@ -49,16 +49,21 @@ #include -#include +#include #include -/** @brief On/off Cluster Server Post Init +/** @brief Level Control Cluster Server Post Init * - * Following resolution of the On/Off state at startup for this endpoint, perform any + * Following resolution of the Level Control state at startup for this endpoint, perform any * additional initialization needed; e.g., synchronize hardware state. * * @param endpoint Endpoint that is being initialized Ver.: always */ void emberAfPluginLevelControlClusterServerPostInitCallback(chip::EndpointId endpoint); -bool HasFeature(chip::EndpointId endpoint, chip::app::Clusters::LevelControl::LevelControlFeature feature); +/** + * Check whether the instance of the Level Control cluster on the given endpoint + * has the given feature. The implementation is allowed to assume there is in + * fact an instance of Level Control on the given endpoint. + */ +bool LevelControlHasFeature(chip::EndpointId endpoint, chip::app::Clusters::LevelControl::LevelControlFeature feature); diff --git a/src/app/clusters/on-off-server/on-off-server.cpp b/src/app/clusters/on-off-server/on-off-server.cpp index b24ee63efe9042..b84a1bab6f13f4 100644 --- a/src/app/clusters/on-off-server/on-off-server.cpp +++ b/src/app/clusters/on-off-server/on-off-server.cpp @@ -51,6 +51,10 @@ #include #endif // EMBER_AF_PLUGIN_SCENES +#ifdef EMBER_AF_PLUGIN_LEVEL_CONTROL +#include +#endif // EMBER_AF_PLUGIN_LEVEL_CONTROL + using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::OnOff; @@ -100,6 +104,18 @@ EmberAfStatus OnOffServer::getOnOffValue(chip::EndpointId endpoint, bool * curre return status; } +#ifdef EMBER_AF_PLUGIN_LEVEL_CONTROL +static bool LevelControlWithOnOffFeaturePresent(EndpointId endpoint) +{ + if (!emberAfContainsServer(endpoint, LevelControl::Id)) + { + return false; + } + + return LevelControlHasFeature(endpoint, LevelControl::LevelControlFeature::kOnOff); +} +#endif // EMBER_AF_PLUGIN_LEVEL_CONTROL + /** @brief On/off Cluster Set Value * * This function is called when the on/off value needs to be set, either through @@ -176,7 +192,7 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, uint8_t comm #ifdef EMBER_AF_PLUGIN_LEVEL_CONTROL // If initiatedByLevelChange is false, then we assume that the level change // ZCL stuff has not happened and we do it here - if (!initiatedByLevelChange && emberAfContainsServer(endpoint, LevelControl::Id)) + if (!initiatedByLevelChange && LevelControlWithOnOffFeaturePresent(endpoint)) { emberAfOnOffClusterLevelControlEffectCallback(endpoint, newValue); } @@ -206,7 +222,7 @@ EmberAfStatus OnOffServer::setOnOffValue(chip::EndpointId endpoint, uint8_t comm #ifdef EMBER_AF_PLUGIN_LEVEL_CONTROL // If initiatedByLevelChange is false, then we assume that the level change // ZCL stuff has not happened and we do it here - if (!initiatedByLevelChange && emberAfContainsServer(endpoint, LevelControl::Id)) + if (!initiatedByLevelChange && LevelControlWithOnOffFeaturePresent(endpoint)) { emberAfOnOffClusterLevelControlEffectCallback(endpoint, newValue); }