diff --git a/src/app/clusters/power-source-configuration-server/power-source-configuration-server.cpp b/src/app/clusters/power-source-configuration-server/power-source-configuration-server.cpp new file mode 100644 index 00000000000000..66efc56b2562eb --- /dev/null +++ b/src/app/clusters/power-source-configuration-server/power-source-configuration-server.cpp @@ -0,0 +1,92 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/**************************************************************************** + * @file + * @brief Implementation for the Descriptor Server Cluster + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::PowerSourceConfiguration::Attributes; + +namespace { + +class PowerSourceConfigurationAttrAccess : public AttributeAccessInterface +{ +public: + // Register on all endpoints. + PowerSourceConfigurationAttrAccess() : AttributeAccessInterface(Optional::Missing(), PowerSourceConfiguration::Id) + {} + + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; +}; + +PowerSourceConfigurationAttrAccess gAttrAccess; + +CHIP_ERROR PowerSourceConfigurationAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) +{ + VerifyOrDie(aPath.mClusterId == PowerSourceConfiguration::Id); + CHIP_ERROR err = CHIP_NO_ERROR; + + if (aPath.mAttributeId == Sources::Id) + { + if (aPath.mEndpointId == 0x00) + { + err = aEncoder.EncodeList([](const TagBoundEncoder & encoder) -> CHIP_ERROR { + uint16_t clusterCount = 0; + + for (uint16_t index = 0; index < emberAfEndpointCount(); index++) + { + clusterCount = emberAfClusterCount(index, true); + + for (uint8_t clusterIndex = 0; clusterIndex < clusterCount; clusterIndex++) + { + EmberAfCluster * cluster = emberAfGetNthCluster(index, clusterIndex, true); + + if (cluster->clusterId == PowerSource::Id) + { + ReturnErrorOnFailure(encoder.Encode(index)); + break; // There is only 1 server cluster per endpoint + } + } + } + + return CHIP_NO_ERROR; + }); + } + } + + return CHIP_NO_ERROR; +} + +} // anonymous namespace + +void MatterPowerSourceConfigurationPluginServerInitCallback(void) +{ + registerAttributeAccessOverride(&gAttrAccess); +} diff --git a/src/app/util/util.cpp b/src/app/util/util.cpp index 77d8c98034faab..b7b3eba24c6370 100644 --- a/src/app/util/util.cpp +++ b/src/app/util/util.cpp @@ -307,7 +307,6 @@ void MatterFlowMeasurementPluginServerInitCallback() {} void MatterWakeOnLanPluginServerInitCallback() {} void MatterOnOffSwitchConfigurationPluginServerInitCallback() {} void MatterPowerSourcePluginServerInitCallback() {} -void MatterPowerSourceConfigurationPluginServerInitCallback() {} void MatterThermostatUserInterfaceConfigurationPluginServerInitCallback() {} void MatterBridgedDeviceBasicInformationPluginServerInitCallback() {} diff --git a/src/app/zap_cluster_list.py b/src/app/zap_cluster_list.py index 3b0686aadc6008..18a0a70f89f547 100755 --- a/src/app/zap_cluster_list.py +++ b/src/app/zap_cluster_list.py @@ -54,7 +54,7 @@ 'OTA_PROVIDER_CLUSTER': ['ota-provider'], 'OTA_REQUESTOR_CLUSTER': [], 'POWER_SOURCE_CLUSTER': [], - 'POWER_SOURCE_CONFIGURATION_CLUSTER': [], + 'POWER_SOURCE_CONFIGURATION_CLUSTER': ['power-source-configuration-server'], 'PRESSURE_MEASUREMENT_CLUSTER': [], 'PUMP_CONFIG_CONTROL_CLUSTER': ['pump-configuration-and-control-server'], 'RELATIVE_HUMIDITY_MEASUREMENT_CLUSTER': [],