Skip to content

Commit

Permalink
Remove LevelControlFeature from the allow list of defines (project-ch…
Browse files Browse the repository at this point in the history
…ip#25369)

* Remove LevelControlFeature from the allow list of defines

* Update generated code
  • Loading branch information
vivien-apple authored and David Lechner committed Mar 22, 2023
1 parent b810c2e commit bd82429
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
89 changes: 88 additions & 1 deletion src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,94 @@ void emberAfLevelControlClusterServerInitCallback(EndpointId endpoint)
return;
}

levelControlClusterServerInit(endpoint, state);
state->minLevel = EMBER_AF_PLUGIN_LEVEL_CONTROL_MINIMUM_LEVEL;
state->maxLevel = EMBER_AF_PLUGIN_LEVEL_CONTROL_MAXIMUM_LEVEL;

// If these read only attributes are enabled we use those values as our set minLevel and maxLevel
// if get isn't possible, value stays at default
Attributes::MinLevel::Get(endpoint, &state->minLevel);
Attributes::MaxLevel::Get(endpoint, &state->maxLevel);

if (LevelControlHasFeature(endpoint, LevelControlFeature::kLighting))
{
if (state->minLevel < LEVEL_CONTROL_LIGHTING_MIN_LEVEL)
{
state->minLevel = LEVEL_CONTROL_LIGHTING_MIN_LEVEL;
}

if (state->maxLevel > LEVEL_CONTROL_LIGHTING_MAX_LEVEL)
{
state->maxLevel = LEVEL_CONTROL_LIGHTING_MAX_LEVEL;
}
}

app::DataModel::Nullable<uint8_t> currentLevel;
EmberAfStatus status = Attributes::CurrentLevel::Get(endpoint, currentLevel);
if (status == EMBER_ZCL_STATUS_SUCCESS)
{
#ifndef IGNORE_LEVEL_CONTROL_CLUSTER_START_UP_CURRENT_LEVEL
// StartUp behavior relies StartUpCurrentLevel attributes being Non Volatile.
if (areStartUpLevelControlServerAttributesNonVolatile(endpoint))
{
// 1.5.14. StartUpCurrentLevel Attribute
// The StartUpCurrentLevel attribute SHALL define the desired startup level
// for a device when it is supplied with power and this level SHALL be
// reflected in the CurrentLevel attribute. The values of the StartUpCurrentLevel
// attribute are listed below:
// Table 4. Values of the StartUpCurrentLevel attribute
// Value Action on power up
// 0x00 Set the CurrentLevel attribute to the minimum value permitted on the device.
// 0x01-0xfe Set the CurrentLevel attribute to this value.
// NULL Set the CurrentLevel attribute to its previous value.
// 0xFF Work Around ZAP Can't set default value to NULL
// https://github.com/project-chip/zap/issues/354

app::DataModel::Nullable<uint8_t> startUpCurrentLevel;
status = Attributes::StartUpCurrentLevel::Get(endpoint, startUpCurrentLevel);
if (status == EMBER_ZCL_STATUS_SUCCESS)
{
if (!startUpCurrentLevel.IsNull())
{
if (startUpCurrentLevel.Value() == STARTUP_CURRENT_LEVEL_USE_DEVICE_MINIMUM)
{
currentLevel.SetNonNull(state->minLevel);
}
else
{
// Otherwise set to specified value 0x01-0xFE.
// But, need to enforce currentLevel's min/max, right?
// Spec doesn't mention this.
if (startUpCurrentLevel.Value() < state->minLevel)
{
currentLevel.SetNonNull(state->minLevel);
}
else if (startUpCurrentLevel.Value() > state->maxLevel)
{
currentLevel.SetNonNull(state->maxLevel);
}
else
{
currentLevel.SetNonNull(startUpCurrentLevel.Value());
}
}
}
// Otherwise Set the CurrentLevel attribute to its previous value which was already fetch above

Attributes::CurrentLevel::Set(endpoint, currentLevel);
}
}
#endif // IGNORE_LEVEL_CONTROL_CLUSTER_START_UP_CURRENT_LEVEL
// In any case, we make sure that the respects min/max
if (currentLevel.IsNull() || currentLevel.Value() < state->minLevel)
{
Attributes::CurrentLevel::Set(endpoint, state->minLevel);
}
else if (currentLevel.Value() > state->maxLevel)
{
Attributes::CurrentLevel::Set(endpoint, state->maxLevel);
}
}

emberAfPluginLevelControlClusterServerPostInitCallback(endpoint);
}

Expand Down
1 change: 0 additions & 1 deletion src/app/common/templates/config-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ DefineBitmaps:
- BarrierControlCapabilities
- BarrierControlSafetyStatus
- ColorLoopUpdateFlags
- LevelControlFeature

# We need a more configurable way of deciding which clusters have which init functions....
# See https://github.com/project-chip/connectedhomeip/issues/4369
Expand Down
6 changes: 0 additions & 6 deletions zzz_generated/app-common/app-common/zap-generated/enums.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd82429

Please sign in to comment.