ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
climate_traits.h
Go to the documentation of this file.
1#pragma once
2
4#include "climate_mode.h"
5#include <set>
6
7namespace esphome {
8
9#ifdef USE_API
10namespace api {
11class APIConnection;
12} // namespace api
13#endif
14
15namespace climate {
16
49 public:
51 void set_supports_current_temperature(bool supports_current_temperature) {
52 this->supports_current_temperature_ = supports_current_temperature;
53 }
55 void set_supports_current_humidity(bool supports_current_humidity) {
56 this->supports_current_humidity_ = supports_current_humidity;
57 }
59 void set_supports_two_point_target_temperature(bool supports_two_point_target_temperature) {
60 this->supports_two_point_target_temperature_ = supports_two_point_target_temperature;
61 }
63 void set_supports_target_humidity(bool supports_target_humidity) {
64 this->supports_target_humidity_ = supports_target_humidity;
65 }
66 void set_supported_modes(std::set<ClimateMode> modes) { this->supported_modes_ = std::move(modes); }
68 ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
69 void set_supports_auto_mode(bool supports_auto_mode) { set_mode_support_(CLIMATE_MODE_AUTO, supports_auto_mode); }
70 ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
71 void set_supports_cool_mode(bool supports_cool_mode) { set_mode_support_(CLIMATE_MODE_COOL, supports_cool_mode); }
72 ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
73 void set_supports_heat_mode(bool supports_heat_mode) { set_mode_support_(CLIMATE_MODE_HEAT, supports_heat_mode); }
74 ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
75 void set_supports_heat_cool_mode(bool supported) { set_mode_support_(CLIMATE_MODE_HEAT_COOL, supported); }
76 ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
77 void set_supports_fan_only_mode(bool supports_fan_only_mode) {
78 set_mode_support_(CLIMATE_MODE_FAN_ONLY, supports_fan_only_mode);
79 }
80 ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
81 void set_supports_dry_mode(bool supports_dry_mode) { set_mode_support_(CLIMATE_MODE_DRY, supports_dry_mode); }
82 bool supports_mode(ClimateMode mode) const { return this->supported_modes_.count(mode); }
83 const std::set<ClimateMode> &get_supported_modes() const { return this->supported_modes_; }
84
85 void set_supports_action(bool supports_action) { this->supports_action_ = supports_action; }
86 bool get_supports_action() const { return this->supports_action_; }
87
88 void set_supported_fan_modes(std::set<ClimateFanMode> modes) { this->supported_fan_modes_ = std::move(modes); }
90 void add_supported_custom_fan_mode(const std::string &mode) { this->supported_custom_fan_modes_.insert(mode); }
91 ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
92 void set_supports_fan_mode_on(bool supported) { set_fan_mode_support_(CLIMATE_FAN_ON, supported); }
93 ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
94 void set_supports_fan_mode_off(bool supported) { set_fan_mode_support_(CLIMATE_FAN_OFF, supported); }
95 ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
96 void set_supports_fan_mode_auto(bool supported) { set_fan_mode_support_(CLIMATE_FAN_AUTO, supported); }
97 ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
98 void set_supports_fan_mode_low(bool supported) { set_fan_mode_support_(CLIMATE_FAN_LOW, supported); }
99 ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
100 void set_supports_fan_mode_medium(bool supported) { set_fan_mode_support_(CLIMATE_FAN_MEDIUM, supported); }
101 ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
102 void set_supports_fan_mode_high(bool supported) { set_fan_mode_support_(CLIMATE_FAN_HIGH, supported); }
103 ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
104 void set_supports_fan_mode_middle(bool supported) { set_fan_mode_support_(CLIMATE_FAN_MIDDLE, supported); }
105 ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
106 void set_supports_fan_mode_focus(bool supported) { set_fan_mode_support_(CLIMATE_FAN_FOCUS, supported); }
107 ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
108 void set_supports_fan_mode_diffuse(bool supported) { set_fan_mode_support_(CLIMATE_FAN_DIFFUSE, supported); }
109 bool supports_fan_mode(ClimateFanMode fan_mode) const { return this->supported_fan_modes_.count(fan_mode); }
111 return !this->supported_fan_modes_.empty() || !this->supported_custom_fan_modes_.empty();
112 }
113 const std::set<ClimateFanMode> &get_supported_fan_modes() const { return this->supported_fan_modes_; }
114
115 void set_supported_custom_fan_modes(std::set<std::string> supported_custom_fan_modes) {
116 this->supported_custom_fan_modes_ = std::move(supported_custom_fan_modes);
117 }
118 const std::set<std::string> &get_supported_custom_fan_modes() const { return this->supported_custom_fan_modes_; }
119 bool supports_custom_fan_mode(const std::string &custom_fan_mode) const {
120 return this->supported_custom_fan_modes_.count(custom_fan_mode);
121 }
122
123 void set_supported_presets(std::set<ClimatePreset> presets) { this->supported_presets_ = std::move(presets); }
125 void add_supported_custom_preset(const std::string &preset) { this->supported_custom_presets_.insert(preset); }
126 bool supports_preset(ClimatePreset preset) const { return this->supported_presets_.count(preset); }
127 bool get_supports_presets() const { return !this->supported_presets_.empty(); }
128 const std::set<climate::ClimatePreset> &get_supported_presets() const { return this->supported_presets_; }
129
130 void set_supported_custom_presets(std::set<std::string> supported_custom_presets) {
131 this->supported_custom_presets_ = std::move(supported_custom_presets);
132 }
133 const std::set<std::string> &get_supported_custom_presets() const { return this->supported_custom_presets_; }
134 bool supports_custom_preset(const std::string &custom_preset) const {
135 return this->supported_custom_presets_.count(custom_preset);
136 }
137
138 void set_supported_swing_modes(std::set<ClimateSwingMode> modes) { this->supported_swing_modes_ = std::move(modes); }
140 ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
141 void set_supports_swing_mode_off(bool supported) { set_swing_mode_support_(CLIMATE_SWING_OFF, supported); }
142 ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
143 void set_supports_swing_mode_both(bool supported) { set_swing_mode_support_(CLIMATE_SWING_BOTH, supported); }
144 ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
145 void set_supports_swing_mode_vertical(bool supported) { set_swing_mode_support_(CLIMATE_SWING_VERTICAL, supported); }
146 ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
147 void set_supports_swing_mode_horizontal(bool supported) {
149 }
150 bool supports_swing_mode(ClimateSwingMode swing_mode) const { return this->supported_swing_modes_.count(swing_mode); }
151 bool get_supports_swing_modes() const { return !this->supported_swing_modes_.empty(); }
152 const std::set<ClimateSwingMode> &get_supported_swing_modes() const { return this->supported_swing_modes_; }
153
155 void set_visual_min_temperature(float visual_min_temperature) {
156 this->visual_min_temperature_ = visual_min_temperature;
157 }
159 void set_visual_max_temperature(float visual_max_temperature) {
160 this->visual_max_temperature_ = visual_max_temperature;
161 }
164 void set_visual_target_temperature_step(float temperature_step) {
165 this->visual_target_temperature_step_ = temperature_step;
166 }
167 void set_visual_current_temperature_step(float temperature_step) {
168 this->visual_current_temperature_step_ = temperature_step;
169 }
170 void set_visual_temperature_step(float temperature_step) {
171 this->visual_target_temperature_step_ = temperature_step;
172 this->visual_current_temperature_step_ = temperature_step;
173 }
176
177 float get_visual_min_humidity() const { return this->visual_min_humidity_; }
178 void set_visual_min_humidity(float visual_min_humidity) { this->visual_min_humidity_ = visual_min_humidity; }
179 float get_visual_max_humidity() const { return this->visual_max_humidity_; }
180 void set_visual_max_humidity(float visual_max_humidity) { this->visual_max_humidity_ = visual_max_humidity; }
181
182 protected:
183#ifdef USE_API
184 // The API connection is a friend class to access internal methods
185 friend class api::APIConnection;
186 // These methods return references to internal data structures.
187 // They are used by the API to avoid copying data when encoding messages.
188 // Warning: Do not use these methods outside of the API connection code.
189 // They return references to internal data that can be invalidated.
190 const std::set<ClimateMode> &get_supported_modes_for_api_() const { return this->supported_modes_; }
191 const std::set<ClimateFanMode> &get_supported_fan_modes_for_api_() const { return this->supported_fan_modes_; }
192 const std::set<std::string> &get_supported_custom_fan_modes_for_api_() const {
193 return this->supported_custom_fan_modes_;
194 }
195 const std::set<climate::ClimatePreset> &get_supported_presets_for_api_() const { return this->supported_presets_; }
196 const std::set<std::string> &get_supported_custom_presets_for_api_() const { return this->supported_custom_presets_; }
197 const std::set<ClimateSwingMode> &get_supported_swing_modes_for_api_() const { return this->supported_swing_modes_; }
198#endif
199
201 if (supported) {
202 this->supported_modes_.insert(mode);
203 } else {
204 this->supported_modes_.erase(mode);
205 }
206 }
208 if (supported) {
209 this->supported_fan_modes_.insert(mode);
210 } else {
211 this->supported_fan_modes_.erase(mode);
212 }
213 }
215 if (supported) {
216 this->supported_swing_modes_.insert(mode);
217 } else {
218 this->supported_swing_modes_.erase(mode);
219 }
220 }
221
226 std::set<climate::ClimateMode> supported_modes_ = {climate::CLIMATE_MODE_OFF};
227 bool supports_action_{false};
228 std::set<climate::ClimateFanMode> supported_fan_modes_;
229 std::set<climate::ClimateSwingMode> supported_swing_modes_;
230 std::set<climate::ClimatePreset> supported_presets_;
231 std::set<std::string> supported_custom_fan_modes_;
232 std::set<std::string> supported_custom_presets_;
233
240};
241
242} // namespace climate
243} // namespace esphome
BedjetMode mode
BedJet operating mode.
This class contains all static data for climate devices.
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_heat_cool_mode(bool supported)
void set_visual_max_temperature(float visual_max_temperature)
const std::set< std::string > & get_supported_custom_presets_for_api_() const
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_dry_mode(bool supports_dry_mode)
std::set< climate::ClimateMode > supported_modes_
void set_supported_modes(std::set< ClimateMode > modes)
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_fan_only_mode(bool supports_fan_only_mode)
const std::set< ClimateFanMode > & get_supported_fan_modes_for_api_() const
const std::set< climate::ClimatePreset > & get_supported_presets() const
void set_supported_custom_fan_modes(std::set< std::string > supported_custom_fan_modes)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_high(bool supported)
const std::set< ClimateMode > & get_supported_modes_for_api_() const
void add_supported_fan_mode(ClimateFanMode mode)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_low(bool supported)
std::set< std::string > supported_custom_fan_modes_
void set_supports_action(bool supports_action)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_middle(bool supported)
void set_supported_custom_presets(std::set< std::string > supported_custom_presets)
bool get_supports_current_temperature() const
std::set< climate::ClimatePreset > supported_presets_
ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20") void set_supports_swing_mode_horizontal(bool supported)
void set_supports_current_humidity(bool supports_current_humidity)
void add_supported_custom_preset(const std::string &preset)
void set_visual_temperature_step(float temperature_step)
void add_supported_preset(ClimatePreset preset)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_on(bool supported)
void set_visual_target_temperature_step(float temperature_step)
void set_supports_two_point_target_temperature(bool supports_two_point_target_temperature)
void add_supported_custom_fan_mode(const std::string &mode)
float get_visual_current_temperature_step() const
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_cool_mode(bool supports_cool_mode)
const std::set< ClimateSwingMode > & get_supported_swing_modes_for_api_() const
void set_visual_min_temperature(float visual_min_temperature)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_off(bool supported)
void set_supported_swing_modes(std::set< ClimateSwingMode > modes)
bool supports_mode(ClimateMode mode) const
int8_t get_target_temperature_accuracy_decimals() const
float get_visual_target_temperature_step() const
void set_visual_min_humidity(float visual_min_humidity)
bool supports_custom_preset(const std::string &custom_preset) const
ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20") void set_supports_swing_mode_both(bool supported)
void set_visual_current_temperature_step(float temperature_step)
void set_supports_target_humidity(bool supports_target_humidity)
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_auto_mode(bool supports_auto_mode)
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_heat_mode(bool supports_heat_mode)
int8_t get_current_temperature_accuracy_decimals() const
const std::set< climate::ClimatePreset > & get_supported_presets_for_api_() const
void set_visual_max_humidity(float visual_max_humidity)
void set_supported_presets(std::set< ClimatePreset > presets)
bool supports_fan_mode(ClimateFanMode fan_mode) const
void add_supported_mode(ClimateMode mode)
bool supports_custom_fan_mode(const std::string &custom_fan_mode) const
void set_swing_mode_support_(climate::ClimateSwingMode mode, bool supported)
const std::set< std::string > & get_supported_custom_fan_modes_for_api_() const
ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20") void set_supports_swing_mode_vertical(bool supported)
bool supports_preset(ClimatePreset preset) const
const std::set< std::string > & get_supported_custom_fan_modes() const
void set_supported_fan_modes(std::set< ClimateFanMode > modes)
void set_supports_current_temperature(bool supports_current_temperature)
std::set< std::string > supported_custom_presets_
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_auto(bool supported)
std::set< climate::ClimateFanMode > supported_fan_modes_
const std::set< std::string > & get_supported_custom_presets() const
bool get_supports_two_point_target_temperature() const
const std::set< ClimateFanMode > & get_supported_fan_modes() const
void set_fan_mode_support_(climate::ClimateFanMode mode, bool supported)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_medium(bool supported)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_diffuse(bool supported)
void add_supported_swing_mode(ClimateSwingMode mode)
ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20") void set_supports_swing_mode_off(bool supported)
const std::set< ClimateMode > & get_supported_modes() const
const std::set< ClimateSwingMode > & get_supported_swing_modes() const
std::set< climate::ClimateSwingMode > supported_swing_modes_
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_focus(bool supported)
bool supports_swing_mode(ClimateSwingMode swing_mode) const
void set_mode_support_(climate::ClimateMode mode, bool supported)
ClimateSwingMode swing_mode
Definition climate.h:11
uint8_t custom_preset
Definition climate.h:9
ClimateFanMode fan_mode
Definition climate.h:3
ClimatePreset preset
Definition climate.h:8
uint8_t custom_fan_mode
Definition climate.h:4
ClimatePreset
Enum for all preset modes.
ClimateSwingMode
Enum for all modes a climate swing can be in.
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
ClimateMode
Enum for all modes a climate device can be in.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
@ CLIMATE_MODE_AUTO
The climate device is adjusting the temperature dynamically.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_DIFFUSE
The fan mode is set to Diffuse.
@ CLIMATE_FAN_ON
The fan mode is set to On.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_FOCUS
The fan mode is set to Focus.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_MIDDLE
The fan mode is set to Middle.
@ CLIMATE_FAN_OFF
The fan mode is set to Off.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7