Skip to content

Commit 1093512

Browse files
lpbeliveau-silabsjmartinez-silabs
authored andcommitted
[Scenes] Level control handler bugfix (#29076)
* Used NumericAttributesTraits for storage null values, removed un-necessary typing and added doc on on-off and level control handlers interactions * Update src/app/clusters/on-off-server/on-off-server.cpp Co-authored-by: Junior Martinez <[email protected]> --------- Co-authored-by: Junior Martinez <[email protected]>
1 parent 2e0f0e7 commit 1093512

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/app/clusters/level-control/level-control.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,16 @@ class DefaultLevelControlSceneHandler : public scenes::DefaultSceneHandlerImpl
171171
uint8_t maxLevel;
172172
VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == Attributes::MaxLevel::Get(endpoint, &maxLevel), CHIP_ERROR_READ_FAILED);
173173

174-
pairs[0].attributeID = Attributes::CurrentLevel::Id;
175-
pairs[0].attributeValue = (!level.IsNull()) ? level.Value() : maxLevel + 1;
176-
size_t attributeCount = 1;
174+
pairs[0].attributeID = Attributes::CurrentLevel::Id;
175+
if (!level.IsNull())
176+
{
177+
pairs[0].attributeValue = level.Value();
178+
}
179+
else
180+
{
181+
chip::app::NumericAttributeTraits<uint32_t>::SetNull(pairs[0].attributeValue);
182+
}
183+
size_t attributeCount = 1;
177184
if (LevelControlHasFeature(endpoint, LevelControl::Feature::kFrequency))
178185
{
179186
uint16_t frequency;
@@ -238,9 +245,9 @@ class DefaultLevelControlSceneHandler : public scenes::DefaultSceneHandlerImpl
238245
CommandId command = LevelControlHasFeature(endpoint, LevelControl::Feature::kOnOff) ? Commands::MoveToLevelWithOnOff::Id
239246
: Commands::MoveToLevel::Id;
240247

241-
status = moveToLevelHandler(
242-
endpoint, command, level, app::DataModel::MakeNullable<uint16_t>(static_cast<uint16_t>(timeMs / 100)),
243-
chip::Optional<BitMask<LevelControlOptions>>(), chip::Optional<BitMask<LevelControlOptions>>(), INVALID_STORED_LEVEL);
248+
status = moveToLevelHandler(endpoint, command, level, app::DataModel::MakeNullable(static_cast<uint16_t>(timeMs / 100)),
249+
chip::Optional<BitMask<LevelControlOptions>>(), chip::Optional<BitMask<LevelControlOptions>>(),
250+
INVALID_STORED_LEVEL);
244251

245252
if (status != Status::Success)
246253
{

src/app/clusters/on-off-server/on-off-server.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ class DefaultOnOffSceneHandler : public scenes::DefaultSceneHandlerImpl
289289
return err;
290290
}
291291

292+
// This handler assumes it is being used with the default handler for the level control. Therefore if the level control
293+
// cluster with on off feature is present on the endpoint and the level control handler is registered, it assumes this
294+
// handler will take action on the on-off state. This assumes the level control attributes were also saved in the scene.
295+
// This is to prevent a behavior where the on off state is set by this handler, and then the level control handler or vice
296+
// versa.
292297
#ifdef EMBER_AF_PLUGIN_LEVEL_CONTROL
293298
if (!(LevelControlWithOnOffFeaturePresent(endpoint) &&
294299
Scenes::ScenesServer::Instance().IsHandlerRegistered(endpoint, LevelControlServer::GetSceneHandler())))

0 commit comments

Comments
 (0)