Files
esp-matter/components/esp_matter/data_model_provider/clusters/chime/integration.h
T
2026-02-03 15:30:42 +08:00

94 lines
3.1 KiB
C++

// Copyright 2026 Espressif Systems (Shanghai) PTE LTD
//
// 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.
#pragma once
#include <app/clusters/chime-server/ChimeCluster.h>
#include <app/server-cluster/ServerClusterInterfaceRegistry.h>
namespace chip::app::Clusters::Chime {
class ChimeServer {
public:
/**
* Creates a chime server instance. This is just a backwards compatibility wrapper around the ChimeCluster.
* @param aEndpointId The endpoint on which this cluster exists. This must match the zap configuration.
* @param aDelegate A reference to the delegate to be used by this server.
* Note: the caller must ensure that the delegate lives throughout the instance's lifetime.
*/
ChimeServer(EndpointId endpointId, ChimeDelegate &delegate)
: mCluster(endpointId, delegate)
{
}
~ChimeServer();
/**
* Register the chime cluster instance with the ESP-Matter data model provider.
* @return Returns an error if registration fails.
*/
CHIP_ERROR Init();
// Attribute Setters
/**
* Sets the SelectedChime attribute. Note, this also handles writing the new value into non-volatile storage.
* @param chimeSoundID The value to which the SelectedChime is to be set.
* @return Returns a ConstraintError if the chimeSoundID value is not valid. Returns Success otherwise.
*/
Protocols::InteractionModel::Status SetSelectedChime(uint8_t chimeSoundID)
{
return mCluster.Cluster().SetSelectedChime(chimeSoundID);
}
/**
* Sets the Enabled attribute. Note, this also handles writing the new value into non-volatile storage.
* @param Enabled The value to which the Enabled is to be set.
*/
Protocols::InteractionModel::Status SetEnabled(bool enabled)
{
return mCluster.Cluster().SetEnabled(enabled);
}
// Attribute Getters
/**
* @return The Current SelectedChime.
*/
uint8_t GetSelectedChime() const
{
return mCluster.Cluster().GetSelectedChime();
}
/**
* @return The Enabled attribute..
*/
bool GetEnabled() const
{
return mCluster.Cluster().GetEnabled();
}
/**
* @return The endpoint ID.
*/
EndpointId GetEndpointId()
{
return mCluster.Cluster().GetPaths()[0].mEndpointId;
}
// Cluster constants from the spec
static constexpr uint8_t kMaxChimeSoundNameSize = ChimeCluster::kMaxChimeSoundNameSize;
// The Code Driven ChimeCluster instance
chip::app::RegisteredServerCluster<ChimeCluster> mCluster;
};
} // namespace chip::app::Clusters::Chime