Coverage Report

Created: 2026-07-10 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/connectedhomeip/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp
Line
Count
Source
1
#include <app/util/config.h>
2
#include <static-supported-modes-manager.h>
3
4
using namespace chip;
5
using namespace chip::app::Clusters;
6
using namespace chip::app::Clusters::ModeSelect;
7
using chip::Protocols::InteractionModel::Status;
8
9
using ModeOptionStructType = Structs::ModeOptionStruct::Type;
10
using SemanticTag          = Structs::SemanticTagStruct::Type;
11
template <typename T>
12
using List               = app::DataModel::List<T>;
13
using storage_value_type = const ModeOptionStructType;
14
namespace {
15
Structs::ModeOptionStruct::Type buildModeOptionStruct(const char * label, uint8_t mode,
16
                                                      const List<const SemanticTag> & semanticTags)
17
0
{
18
0
    Structs::ModeOptionStruct::Type option;
19
0
    option.label        = CharSpan::fromCharString(label);
20
0
    option.mode         = mode;
21
0
    option.semanticTags = semanticTags;
22
0
    return option;
23
0
}
24
} // namespace
25
26
constexpr SemanticTag semanticTagsBlack[]     = { { .value = 0 } };
27
constexpr SemanticTag semanticTagsCappucino[] = { { .value = 0 } };
28
constexpr SemanticTag semanticTagsEspresso[]  = { { .value = 0 } };
29
30
// TODO: Configure your options for each endpoint
31
storage_value_type StaticSupportedModesManager::coffeeOptions[] = {
32
    buildModeOptionStruct("Black", 0, List<const SemanticTag>(semanticTagsBlack)),
33
    buildModeOptionStruct("Cappuccino", 4, List<const SemanticTag>(semanticTagsCappucino)),
34
    buildModeOptionStruct("Espresso", 7, List<const SemanticTag>(semanticTagsEspresso))
35
};
36
const StaticSupportedModesManager::EndpointSpanPair
37
    StaticSupportedModesManager::supportedOptionsByEndpoints[MATTER_DM_MODE_SELECT_CLUSTER_SERVER_ENDPOINT_COUNT] = {
38
        EndpointSpanPair(1, Span<storage_value_type>(StaticSupportedModesManager::coffeeOptions)) // Options for Endpoint 1
39
    };
40
41
SupportedModesManager::ModeOptionsProvider StaticSupportedModesManager::getModeOptionsProvider(EndpointId endpointId) const
42
0
{
43
0
    for (auto & endpointSpanPair : supportedOptionsByEndpoints)
44
0
    {
45
0
        if (endpointSpanPair.mEndpointId == endpointId)
46
0
        {
47
0
            return ModeOptionsProvider(endpointSpanPair.mSpan.data(), endpointSpanPair.mSpan.end());
48
0
        }
49
0
    }
50
0
    return ModeOptionsProvider(nullptr, nullptr);
51
0
}
52
53
Status StaticSupportedModesManager::getModeOptionByMode(unsigned short endpointId, unsigned char mode,
54
                                                        const ModeOptionStructType ** dataPtr) const
55
0
{
56
0
    auto modeOptionsProvider = this->getModeOptionsProvider(endpointId);
57
0
    if (modeOptionsProvider.begin() == nullptr)
58
0
    {
59
0
        return Status::UnsupportedCluster;
60
0
    }
61
0
    auto * begin = this->getModeOptionsProvider(endpointId).begin();
62
0
    auto * end   = this->getModeOptionsProvider(endpointId).end();
63
64
0
    for (auto * it = begin; it != end; ++it)
65
0
    {
66
0
        auto & modeOption = *it;
67
0
        if (modeOption.mode == mode)
68
0
        {
69
0
            *dataPtr = &modeOption;
70
0
            return Status::Success;
71
0
        }
72
0
    }
73
0
    ChipLogProgress(Zcl, "Cannot find the mode %u", mode);
74
0
    return Status::InvalidCommand;
75
0
}