Coverage Report

Created: 2026-11-12 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/connectedhomeip/src/app/clusters/humidistat-server/CodegenIntegration.cpp
Line
Count
Source
1
/*
2
 *    Copyright (c) 2025 Project CHIP Authors
3
 *    All rights reserved.
4
 *
5
 *    Licensed under the Apache License, Version 2.0 (the "License");
6
 *    you may not use this file except in compliance with the License.
7
 *    You may obtain a copy of the License at
8
 *
9
 *        http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *    Unless required by applicable law or agreed to in writing, software
12
 *    distributed under the License is distributed on an "AS IS" BASIS,
13
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *    See the License for the specific language governing permissions and
15
 *    limitations under the License.
16
 */
17
18
#include "CodegenIntegration.h"
19
20
#include <app-common/zap-generated/attributes/Accessors.h>
21
#include <app/clusters/humidistat-server/HumidistatCluster.h>
22
#include <app/static-cluster-config/Humidistat.h>
23
#include <app/util/attribute-storage.h>
24
#include <data-model-providers/codegen/ClusterIntegration.h>
25
#include <data-model-providers/codegen/CodegenDataModelProvider.h>
26
27
using namespace chip;
28
using namespace chip::app;
29
using namespace chip::app::Clusters;
30
using namespace chip::app::Clusters::Humidistat;
31
32
namespace {
33
34
constexpr size_t kHumidistatFixedClusterCount = Humidistat::StaticApplicationConfig::kFixedClusterConfig.size();
35
constexpr size_t kHumidistatMaxClusterCount   = kHumidistatFixedClusterCount + CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT;
36
37
// Per-instance: each cluster instance gets one LazyRegisteredServerCluster slot.
38
LazyRegisteredServerCluster<HumidistatCluster> gServers[kHumidistatMaxClusterCount];
39
40
class IntegrationDelegate : public CodegenClusterIntegration::Delegate
41
{
42
public:
43
    ServerClusterRegistration & CreateRegistration(EndpointId endpointId, unsigned clusterInstanceIndex,
44
                                                   uint32_t optionalAttributeBits, uint32_t featureMap) override
45
    {
46
        using namespace chip::app::Clusters::Humidistat::Attributes;
47
        using chip::Protocols::InteractionModel::Status;
48
49
        BitFlags<Humidistat::Feature> features(featureMap);
50
51
        // Validate feature dependencies from spec constraints.
52
        VerifyOrDie(!features.Has(Feature::kOptimal) || features.Has(Feature::kSensor));
53
        VerifyOrDie(!features.HasAny(Feature::kColdMist, Feature::kWarmMist) || features.Has(Feature::kHumidifier));
54
        VerifyOrDie(!features.Has(Feature::kAuto) ||
55
                    (features.Has(Feature::kHumidifier) && features.Has(Feature::kDehumidifier) && features.Has(Feature::kSensor)));
56
57
        HumidistatCluster::OptionalAttributeSet optionalAttributes(optionalAttributeBits);
58
59
        // TargetSetpoint is optional only when SENSOR is present.
60
        // When OPTIMAL is enabled (which requires SENSOR), TargetSetpoint is effectively mandatory.
61
        if (!features.Has(Feature::kSensor))
62
        {
63
            optionalAttributes.Set<TargetSetpoint::Id>(false);
64
        }
65
66
        HumidistatCluster::StartupConfiguration config;
67
68
        if (features.Has(Feature::kSensor))
69
        {
70
            VerifyOrDie(MinSetpoint::GetDefault(endpointId, config.minSetpoint) == Status::Success);
71
            VerifyOrDie(MaxSetpoint::GetDefault(endpointId, config.maxSetpoint) == Status::Success);
72
            VerifyOrDie(Step::GetDefault(endpointId, config.step) == Status::Success);
73
74
            chip::Percent percentVal{};
75
            VerifyOrDie(UserSetpoint::GetDefault(endpointId, percentVal) == Status::Success);
76
            config.userSetpoint = percentVal;
77
78
            if (TargetSetpoint::GetDefault(endpointId, percentVal) == Status::Success)
79
            {
80
                config.targetSetpoint = percentVal;
81
            }
82
        }
83
84
        VerifyOrDie(HumidistatMode::GetDefault(endpointId, config.mode) == Status::Success);
85
        VerifyOrDie(HumidistatSystemState::GetDefault(endpointId, config.systemState) == Status::Success);
86
87
        if (features.Has(Feature::kHumidifier))
88
        {
89
            VerifyOrDie(MistType::GetDefault(endpointId, config.mistType) == Status::Success);
90
        }
91
92
        if (features.Has(Feature::kContinuous))
93
        {
94
            VerifyOrDie(Continuous::GetDefault(endpointId, config.continuous) == Status::Success);
95
        }
96
97
        if (optionalAttributes.IsSet(Sleep::Id))
98
        {
99
            Sleep::GetDefaultOr(endpointId, config.sleep, false);
100
        }
101
102
        if (features.Has(Feature::kOptimal))
103
        {
104
            VerifyOrDie(Optimal::GetDefault(endpointId, config.optimal) == Status::Success);
105
            chip::Percent percentVal{};
106
            VerifyOrDie(TargetSetpoint::GetDefault(endpointId, percentVal) == Status::Success);
107
            config.targetSetpoint = percentVal;
108
        }
109
110
        gServers[clusterInstanceIndex].Create(endpointId, features, optionalAttributes, config);
111
        return gServers[clusterInstanceIndex].Registration();
112
    }
113
114
    ServerClusterInterface * FindRegistration(unsigned clusterInstanceIndex) override
115
    {
116
        VerifyOrReturnValue(gServers[clusterInstanceIndex].IsConstructed(), nullptr);
117
        return &gServers[clusterInstanceIndex].Cluster();
118
    }
119
120
    void ReleaseRegistration(unsigned clusterInstanceIndex) override { gServers[clusterInstanceIndex].Destroy(); }
121
};
122
123
} // namespace
124
125
void MatterHumidistatClusterInitCallback(EndpointId endpointId)
126
0
{
127
0
    IntegrationDelegate integrationDelegate;
128
129
0
    CodegenClusterIntegration::RegisterServer(
130
0
        {
131
0
            .endpointId                = endpointId,
132
0
            .clusterId                 = Humidistat::Id,
133
0
            .fixedClusterInstanceCount = kHumidistatFixedClusterCount,
134
0
            .maxClusterInstanceCount   = kHumidistatMaxClusterCount,
135
0
            .fetchFeatureMap           = true,
136
0
            .fetchOptionalAttributes   = true,
137
0
        },
138
0
        integrationDelegate);
139
0
}
140
141
void MatterHumidistatClusterShutdownCallback(EndpointId endpointId, MatterClusterShutdownType shutdownType)
142
0
{
143
0
    IntegrationDelegate integrationDelegate;
144
145
0
    CodegenClusterIntegration::UnregisterServer(
146
0
        {
147
0
            .endpointId                = endpointId,
148
0
            .clusterId                 = Humidistat::Id,
149
0
            .fixedClusterInstanceCount = kHumidistatFixedClusterCount,
150
0
            .maxClusterInstanceCount   = kHumidistatMaxClusterCount,
151
0
        },
152
0
        integrationDelegate, shutdownType);
153
0
}
154
155
0
void MatterHumidistatPluginServerInitCallback() {}
156
157
namespace chip::app::Clusters::Humidistat {
158
159
HumidistatCluster * FindClusterOnEndpoint(EndpointId endpointId)
160
0
{
161
0
    IntegrationDelegate integrationDelegate;
162
163
0
    ServerClusterInterface * cluster = CodegenClusterIntegration::FindClusterOnEndpoint(
164
0
        {
165
0
            .endpointId                = endpointId,
166
0
            .clusterId                 = Humidistat::Id,
167
0
            .fixedClusterInstanceCount = kHumidistatFixedClusterCount,
168
0
            .maxClusterInstanceCount   = kHumidistatMaxClusterCount,
169
0
        },
170
0
        integrationDelegate);
171
172
0
    return cluster != nullptr ? &static_cast<HumidistatCluster &>(*cluster) : nullptr;
173
0
}
174
175
} // namespace chip::app::Clusters::Humidistat