Skip to content

Commit

Permalink
[Scenes] NameSupport Feature (#29639)
Browse files Browse the repository at this point in the history
* Name support is not enforced anymore

* Restyled by clang-format

* Added value initialisation and check on failure of get featuremap before applying a value for namesupport

* Apply suggestions from code review

Co-authored-by: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com>

---------

Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com>
  • Loading branch information
3 people authored and pull[bot] committed Feb 16, 2024
1 parent 47ecdba commit cc09f5b
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions src/app/clusters/scenes-server/scenes-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,35 @@ CHIP_ERROR ScenesServer::Init()

for (auto endpoint : EnabledEndpointsWithServerCluster(Id))
{
// Explicit AttributeValuePairs is mandatory for matter so we force it here, ScenesName is not but it is forced for now
// TODO: We currently force SceneNames on but this needs to be modified to read the value generated from Zap instead.
uint32_t featureMap = to_underlying(Feature::kExplicit) | to_underlying(Feature::kSceneNames);
EmberAfStatus status = Attributes::FeatureMap::Set(endpoint, featureMap);
if (EMBER_ZCL_STATUS_SUCCESS != status)
uint32_t featureMap = 0;
EmberAfStatus status = Attributes::FeatureMap::Get(endpoint, &featureMap);
if (EMBER_ZCL_STATUS_SUCCESS == status)
{
ChipLogDetail(Zcl, "ERR: setting the scenes FeatureMap on Endpoint %hu Status: %x", endpoint, status);
// Setting NameSupport attribute value to 0x80 if the feature bit is set
// The bit of 7 (0x80) the NameSupport attribute indicates whether or not scene names are supported
//
// According to spec, bit 7 (Scene Names) MUST match feature bit 0 (Scene Names)
uint8_t nameSupport =
(featureMap & to_underlying(Feature::kSceneNames)) ? static_cast<uint8_t>(0x80) : static_cast<uint8_t>(0x00);
status = Attributes::NameSupport::Set(endpoint, nameSupport);
if (EMBER_ZCL_STATUS_SUCCESS != status)
{
ChipLogDetail(Zcl, "ERR: setting NameSupport on Endpoint %hu Status: %x", endpoint, status);
}
}
// The bit of 7 the NameSupport attribute indicates whether or not scene names are supported
//
// According to spec, bit 7 (Scene Names) MUST match feature bit 0 (Scene Names)
status = Attributes::NameSupport::Set(endpoint, 0x80);
else
{
ChipLogDetail(Zcl, "ERR: getting the scenes FeatureMap on Endpoint %hu Status: %x", endpoint, status);
}

// Explicit AttributeValuePairs is mandatory for matter so we force it here
featureMap |= to_underlying(Feature::kExplicit);
status = Attributes::FeatureMap::Set(endpoint, featureMap);
if (EMBER_ZCL_STATUS_SUCCESS != status)
{
ChipLogDetail(Zcl, "ERR: setting NameSupport on Endpoint %hu Status: %x", endpoint, status);
ChipLogDetail(Zcl, "ERR: setting the scenes FeatureMap on Endpoint %hu Status: %x", endpoint, status);
}

status = Attributes::LastConfiguredBy::SetNull(endpoint);
if (EMBER_ZCL_STATUS_SUCCESS != status)
{
Expand Down Expand Up @@ -197,7 +210,15 @@ void AddSceneParse(CommandHandlerInterface::HandlerContext & ctx, const CommandD
auto fieldSetIter = req.extensionFieldSets.begin();

uint8_t EFSCount = 0;
SceneData storageData(req.sceneName, transitionTimeMs);

uint32_t featureMap = 0;
ReturnOnFailure(AddResponseOnError(ctx, response, Attributes::FeatureMap::Get(ctx.mRequestPath.mEndpointId, &featureMap)));

SceneData storageData(CharSpan(), transitionTimeMs);
if (featureMap & to_underlying(Feature::kSceneNames))
{
storageData.SetName(req.sceneName);
}

// Goes through all EFS in command
while (fieldSetIter.Next() && EFSCount < scenes::kMaxClustersPerScene)
Expand Down Expand Up @@ -372,6 +393,14 @@ CHIP_ERROR StoreSceneParse(const FabricIndex & fabricIdx, const EndpointId & end
}
else
{
uint32_t featureMap = 0;
ReturnErrorOnFailure(
StatusIB(ToInteractionModelStatus(Attributes::FeatureMap::Get(endpointID, &featureMap))).ToChipError());
// Check if we still support scenes name in case an OTA changed that, if we don't, set name to empty
if (!(featureMap & to_underlying(Feature::kSceneNames)))
{
scene.mStorageData.SetName(CharSpan());
}
scene.mStorageData.mExtensionFieldSets.Clear();
}

Expand Down

0 comments on commit cc09f5b

Please sign in to comment.