Skip to content

Commit e9b7549

Browse files
committed
Rearrange setpoint logic into separate files
1 parent 144cb20 commit e9b7549

13 files changed

Lines changed: 1072 additions & 1388 deletions
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
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+
#pragma once
19+
20+
#include <app/ConcreteAttributePath.h>
21+
#include <app/util/attribute-storage.h>
22+
#include <protocols/interaction_model/Constants.h>
23+
24+
namespace chip {
25+
namespace app {
26+
namespace Clusters {
27+
namespace Thermostat {
28+
29+
enum class SetpointAttributes : uint16_t
30+
{
31+
kNone = 0,
32+
kOccupiedHeating = 1 << 0,
33+
kOccupiedCooling = 1 << 1,
34+
kUnoccupiedHeating = 1 << 2,
35+
kUnoccupiedCooling = 1 << 3,
36+
kMinSetpointDeadBand = 1 << 4,
37+
kMinHeatSetpointLimit = 1 << 5,
38+
kMaxHeatSetpointLimit = 1 << 6,
39+
kMinCoolSetpointLimit = 1 << 7,
40+
kMaxCoolSetpointLimit = 1 << 8,
41+
};
42+
43+
}
44+
} // namespace Clusters
45+
} // namespace app
46+
} // namespace chip
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
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+
#pragma once
19+
20+
#include <app/ConcreteAttributePath.h>
21+
#include <app/util/attribute-storage.h>
22+
#include <protocols/interaction_model/Constants.h>
23+
24+
namespace chip {
25+
namespace app {
26+
namespace Clusters {
27+
namespace Thermostat {
28+
29+
constexpr int16_t kDefaultAbsMinHeatSetpointLimit = 700; // 7C (44.5 F) is the default
30+
constexpr int16_t kDefaultAbsMaxHeatSetpointLimit = 3000; // 30C (86 F) is the default
31+
constexpr int16_t kDefaultAbsMinCoolSetpointLimit = 1600; // 16C (61 F) is the default
32+
constexpr int16_t kDefaultAbsMaxCoolSetpointLimit = 3200; // 32C (90 F) is the default
33+
constexpr int16_t kDefaultDeadBand = 200; // 2.0C is the default
34+
constexpr int16_t kDefaultHeatingSetpoint = 2000;
35+
constexpr int16_t kDefaultCoolingSetpoint = 2600;
36+
37+
} // namespace Thermostat
38+
} // namespace Clusters
39+
} // namespace app
40+
} // namespace chip
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
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 <app-common/zap-generated/attributes/Accessors.h>
19+
#include <app-common/zap-generated/cluster-objects.h>
20+
#include <app-common/zap-generated/ids/Attributes.h>
21+
#include <clusters/Thermostat/Metadata.h>
22+
23+
#include "SetpointLimits.h"
24+
#include "Setpoints.h"
25+
26+
using namespace chip;
27+
using namespace chip::app;
28+
using namespace chip::app::Clusters;
29+
using namespace chip::app::Clusters::Thermostat;
30+
using namespace chip::app::Clusters::Thermostat::Structs;
31+
using namespace chip::app::Clusters::Thermostat::Attributes;
32+
using namespace Protocols::InteractionModel;
33+
34+
namespace chip {
35+
namespace app {
36+
namespace Clusters {
37+
namespace Thermostat {
38+
39+
void calculateEffectiveBounds(const Setpoints & setpoints, SystemModeEnum mode, int16_t & min, int16_t & max)
40+
{
41+
int16_t minHeat = setpoints.heatLimitsOverride.Minimum();
42+
int16_t maxHeat = setpoints.heatLimitsOverride.Maximum();
43+
int16_t minCool = setpoints.coolLimitsOverride.Minimum();
44+
int16_t maxCool = setpoints.coolLimitsOverride.Maximum();
45+
46+
switch (mode)
47+
{
48+
case SystemModeEnum::kHeat:
49+
min = minHeat;
50+
max = setpoints.autoSupported ? maxCool - setpoints.deadBand : maxHeat;
51+
break;
52+
default:
53+
min = setpoints.autoSupported ? maxHeat + setpoints.deadBand : minCool;
54+
max = maxCool;
55+
break;
56+
}
57+
}
58+
59+
EffectiveSetpointLimits::EffectiveSetpointLimits(const Setpoints & setpoints, SystemModeEnum mode) : SetpointAbsoluteLimits(mode), setpoints(setpoints)
60+
{
61+
calculateEffectiveBounds(setpoints, mode, minimum, maximum);
62+
}
63+
64+
65+
} // namespace Thermostat
66+
} // namespace Clusters
67+
} // namespace app
68+
} // namespace chip
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
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+
#pragma once
19+
20+
#include <app/ConcreteAttributePath.h>
21+
#include <app/util/attribute-storage.h>
22+
#include <protocols/interaction_model/Constants.h>
23+
24+
#include "SetpointAttributes.h"
25+
#include "SetpointLimits.h"
26+
27+
namespace chip {
28+
namespace app {
29+
namespace Clusters {
30+
namespace Thermostat {
31+
32+
class Setpoints;
33+
34+
struct SetpointLimits
35+
{
36+
virtual ~SetpointLimits() = default;
37+
virtual int16_t Minimum() const = 0;
38+
virtual int16_t Maximum() const = 0;
39+
bool Valid(int16_t setpoint) const { return setpoint >= Minimum() && setpoint <= Maximum(); };
40+
int16_t Clamp(int16_t setpoint) const { return std::max(Minimum(), std::min(setpoint, Maximum())); };
41+
};
42+
43+
struct SetpointAbsoluteLimits : SetpointLimits
44+
{
45+
chip::app::Clusters::Thermostat::SystemModeEnum mode;
46+
int16_t minimum;
47+
int16_t maximum;
48+
49+
SetpointAbsoluteLimits(chip::app::Clusters::Thermostat::SystemModeEnum mode) : mode(mode) {};
50+
51+
SetpointAbsoluteLimits(const SetpointAbsoluteLimits & limits) : mode(limits.mode), minimum(limits.minimum), maximum(limits.maximum) {};
52+
53+
int16_t Minimum() const override { return minimum; };
54+
int16_t Maximum() const override { return maximum; };
55+
};
56+
57+
struct SetpointLimitOverride : SetpointLimits
58+
{
59+
const SetpointAbsoluteLimits & absoluteLimits;
60+
61+
Optional<int16_t> minimum;
62+
Optional<int16_t> maximum;
63+
64+
SetpointLimitOverride(const SetpointAbsoluteLimits & absoluteLimits) : absoluteLimits(absoluteLimits) {};
65+
SetpointLimitOverride(const SetpointAbsoluteLimits & absoluteLimits, const SetpointLimitOverride & override) : absoluteLimits(absoluteLimits), minimum(override.minimum), maximum(override.maximum) {};
66+
67+
int16_t Minimum() const override { return minimum.HasValue() ? minimum.Value() : absoluteLimits.Minimum(); };
68+
int16_t Maximum() const override { return maximum.HasValue() ? maximum.Value() : absoluteLimits.Maximum(); };
69+
};
70+
71+
struct EffectiveSetpointLimits : SetpointAbsoluteLimits
72+
{
73+
const Setpoints & setpoints;
74+
75+
EffectiveSetpointLimits(const Setpoints & setpoints, chip::app::Clusters::Thermostat::SystemModeEnum mode);
76+
};
77+
78+
} // namespace Thermostat
79+
} // namespace Clusters
80+
} // namespace app
81+
} // namespace chip
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
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 <app-common/zap-generated/attributes/Accessors.h>
19+
#include <app-common/zap-generated/cluster-objects.h>
20+
#include <app-common/zap-generated/ids/Attributes.h>
21+
#include <clusters/Thermostat/Metadata.h>
22+
23+
#include "SetpointRange.h"
24+
#include "Setpoints.h"
25+
26+
using namespace chip;
27+
using namespace chip::app;
28+
using namespace chip::app::Clusters;
29+
using namespace chip::app::Clusters::Thermostat;
30+
using namespace chip::app::Clusters::Thermostat::Structs;
31+
using namespace chip::app::Clusters::Thermostat::Attributes;
32+
using namespace Protocols::InteractionModel;
33+
34+
namespace chip {
35+
namespace app {
36+
namespace Clusters {
37+
namespace Thermostat {} // namespace Thermostat
38+
} // namespace Clusters
39+
} // namespace app
40+
} // namespace chip
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
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+
#pragma once
19+
20+
#include <app/ConcreteAttributePath.h>
21+
#include <app/util/attribute-storage.h>
22+
#include <protocols/interaction_model/Constants.h>
23+
24+
#include "SetpointAttributes.h"
25+
26+
namespace chip {
27+
namespace app {
28+
namespace Clusters {
29+
namespace Thermostat {
30+
31+
class Setpoints;
32+
33+
struct SetpointRange
34+
{
35+
Setpoints & setpoints;
36+
int16_t & heatingSetpoint;
37+
int16_t & coolingSetpoint;
38+
SetpointAttributes heatingAttribute;
39+
SetpointAttributes coolingAttribute;
40+
41+
SetpointRange(Setpoints & setpoints, int16_t & heat, int16_t & cool, SetpointAttributes heatingAttribute,
42+
SetpointAttributes coolingAttribute) :
43+
setpoints(setpoints), heatingSetpoint(heat), coolingSetpoint(cool), heatingAttribute(heatingAttribute),
44+
coolingAttribute(coolingAttribute)
45+
{}
46+
};
47+
48+
} // namespace Thermostat
49+
} // namespace Clusters
50+
} // namespace app
51+
} // namespace chip

0 commit comments

Comments
 (0)