|
| 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 |
0 commit comments