diff --git a/src/app/clusters/scenes-server/scenes-server.cpp b/src/app/clusters/scenes-server/scenes-server.cpp index 92eb4720a4a72e..39bdba86bd90d3 100644 --- a/src/app/clusters/scenes-server/scenes-server.cpp +++ b/src/app/clusters/scenes-server/scenes-server.cpp @@ -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(0x80) : static_cast(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) { @@ -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) @@ -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(); }