ESPHome  2024.11.2
climate_traits.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/helpers.h"
4 #include "climate_mode.h"
5 #include <set>
6 
7 namespace esphome {
8 namespace climate {
9 
42  public:
44  void set_supports_current_temperature(bool supports_current_temperature) {
45  supports_current_temperature_ = supports_current_temperature;
46  }
48  void set_supports_current_humidity(bool supports_current_humidity) {
49  supports_current_humidity_ = supports_current_humidity;
50  }
52  void set_supports_two_point_target_temperature(bool supports_two_point_target_temperature) {
53  supports_two_point_target_temperature_ = supports_two_point_target_temperature;
54  }
56  void set_supports_target_humidity(bool supports_target_humidity) {
57  supports_target_humidity_ = supports_target_humidity;
58  }
59  void set_supported_modes(std::set<ClimateMode> modes) { supported_modes_ = std::move(modes); }
61  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
62  void set_supports_auto_mode(bool supports_auto_mode) { set_mode_support_(CLIMATE_MODE_AUTO, supports_auto_mode); }
63  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
64  void set_supports_cool_mode(bool supports_cool_mode) { set_mode_support_(CLIMATE_MODE_COOL, supports_cool_mode); }
65  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
66  void set_supports_heat_mode(bool supports_heat_mode) { set_mode_support_(CLIMATE_MODE_HEAT, supports_heat_mode); }
67  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
68  void set_supports_heat_cool_mode(bool supported) { set_mode_support_(CLIMATE_MODE_HEAT_COOL, supported); }
69  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
70  void set_supports_fan_only_mode(bool supports_fan_only_mode) {
71  set_mode_support_(CLIMATE_MODE_FAN_ONLY, supports_fan_only_mode);
72  }
73  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
74  void set_supports_dry_mode(bool supports_dry_mode) { set_mode_support_(CLIMATE_MODE_DRY, supports_dry_mode); }
75  bool supports_mode(ClimateMode mode) const { return supported_modes_.count(mode); }
76  const std::set<ClimateMode> &get_supported_modes() const { return supported_modes_; }
77 
78  void set_supports_action(bool supports_action) { supports_action_ = supports_action; }
79  bool get_supports_action() const { return supports_action_; }
80 
81  void set_supported_fan_modes(std::set<ClimateFanMode> modes) { supported_fan_modes_ = std::move(modes); }
83  void add_supported_custom_fan_mode(const std::string &mode) { supported_custom_fan_modes_.insert(mode); }
84  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
85  void set_supports_fan_mode_on(bool supported) { set_fan_mode_support_(CLIMATE_FAN_ON, supported); }
86  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
87  void set_supports_fan_mode_off(bool supported) { set_fan_mode_support_(CLIMATE_FAN_OFF, supported); }
88  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
89  void set_supports_fan_mode_auto(bool supported) { set_fan_mode_support_(CLIMATE_FAN_AUTO, supported); }
90  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
91  void set_supports_fan_mode_low(bool supported) { set_fan_mode_support_(CLIMATE_FAN_LOW, supported); }
92  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
93  void set_supports_fan_mode_medium(bool supported) { set_fan_mode_support_(CLIMATE_FAN_MEDIUM, supported); }
94  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
95  void set_supports_fan_mode_high(bool supported) { set_fan_mode_support_(CLIMATE_FAN_HIGH, supported); }
96  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
97  void set_supports_fan_mode_middle(bool supported) { set_fan_mode_support_(CLIMATE_FAN_MIDDLE, supported); }
98  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
99  void set_supports_fan_mode_focus(bool supported) { set_fan_mode_support_(CLIMATE_FAN_FOCUS, supported); }
100  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
101  void set_supports_fan_mode_diffuse(bool supported) { set_fan_mode_support_(CLIMATE_FAN_DIFFUSE, supported); }
102  bool supports_fan_mode(ClimateFanMode fan_mode) const { return supported_fan_modes_.count(fan_mode); }
103  bool get_supports_fan_modes() const { return !supported_fan_modes_.empty() || !supported_custom_fan_modes_.empty(); }
104  const std::set<ClimateFanMode> &get_supported_fan_modes() const { return supported_fan_modes_; }
105 
106  void set_supported_custom_fan_modes(std::set<std::string> supported_custom_fan_modes) {
107  supported_custom_fan_modes_ = std::move(supported_custom_fan_modes);
108  }
109  const std::set<std::string> &get_supported_custom_fan_modes() const { return supported_custom_fan_modes_; }
110  bool supports_custom_fan_mode(const std::string &custom_fan_mode) const {
111  return supported_custom_fan_modes_.count(custom_fan_mode);
112  }
113 
114  void set_supported_presets(std::set<ClimatePreset> presets) { supported_presets_ = std::move(presets); }
116  void add_supported_custom_preset(const std::string &preset) { supported_custom_presets_.insert(preset); }
117  bool supports_preset(ClimatePreset preset) const { return supported_presets_.count(preset); }
118  bool get_supports_presets() const { return !supported_presets_.empty(); }
119  const std::set<climate::ClimatePreset> &get_supported_presets() const { return supported_presets_; }
120 
121  void set_supported_custom_presets(std::set<std::string> supported_custom_presets) {
122  supported_custom_presets_ = std::move(supported_custom_presets);
123  }
124  const std::set<std::string> &get_supported_custom_presets() const { return supported_custom_presets_; }
125  bool supports_custom_preset(const std::string &custom_preset) const {
126  return supported_custom_presets_.count(custom_preset);
127  }
128 
129  void set_supported_swing_modes(std::set<ClimateSwingMode> modes) { supported_swing_modes_ = std::move(modes); }
131  ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
132  void set_supports_swing_mode_off(bool supported) { set_swing_mode_support_(CLIMATE_SWING_OFF, supported); }
133  ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
134  void set_supports_swing_mode_both(bool supported) { set_swing_mode_support_(CLIMATE_SWING_BOTH, supported); }
135  ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
136  void set_supports_swing_mode_vertical(bool supported) { set_swing_mode_support_(CLIMATE_SWING_VERTICAL, supported); }
137  ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
138  void set_supports_swing_mode_horizontal(bool supported) {
140  }
141  bool supports_swing_mode(ClimateSwingMode swing_mode) const { return supported_swing_modes_.count(swing_mode); }
142  bool get_supports_swing_modes() const { return !supported_swing_modes_.empty(); }
143  const std::set<ClimateSwingMode> &get_supported_swing_modes() const { return supported_swing_modes_; }
144 
146  void set_visual_min_temperature(float visual_min_temperature) { visual_min_temperature_ = visual_min_temperature; }
148  void set_visual_max_temperature(float visual_max_temperature) { visual_max_temperature_ = visual_max_temperature; }
151  void set_visual_target_temperature_step(float temperature_step) {
152  visual_target_temperature_step_ = temperature_step;
153  }
154  void set_visual_current_temperature_step(float temperature_step) {
155  visual_current_temperature_step_ = temperature_step;
156  }
157  void set_visual_temperature_step(float temperature_step) {
158  visual_target_temperature_step_ = temperature_step;
159  visual_current_temperature_step_ = temperature_step;
160  }
163 
165  void set_visual_min_humidity(float visual_min_humidity) { visual_min_humidity_ = visual_min_humidity; }
167  void set_visual_max_humidity(float visual_max_humidity) { visual_max_humidity_ = visual_max_humidity; }
168 
169  protected:
171  if (supported) {
172  supported_modes_.insert(mode);
173  } else {
174  supported_modes_.erase(mode);
175  }
176  }
178  if (supported) {
179  supported_fan_modes_.insert(mode);
180  } else {
181  supported_fan_modes_.erase(mode);
182  }
183  }
185  if (supported) {
186  supported_swing_modes_.insert(mode);
187  } else {
188  supported_swing_modes_.erase(mode);
189  }
190  }
191 
196  std::set<climate::ClimateMode> supported_modes_ = {climate::CLIMATE_MODE_OFF};
197  bool supports_action_{false};
198  std::set<climate::ClimateFanMode> supported_fan_modes_;
199  std::set<climate::ClimateSwingMode> supported_swing_modes_;
200  std::set<climate::ClimatePreset> supported_presets_;
201  std::set<std::string> supported_custom_fan_modes_;
202  std::set<std::string> supported_custom_presets_;
203 
210 };
211 
212 } // namespace climate
213 } // namespace esphome
The fan mode is set to Low.
Definition: climate_mode.h:54
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_heat_cool_mode(bool supported)
void set_visual_min_humidity(float visual_min_humidity)
std::set< climate::ClimateSwingMode > supported_swing_modes_
void set_supported_custom_presets(std::set< std::string > supported_custom_presets)
void set_visual_temperature_step(float temperature_step)
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_dry_mode(bool supports_dry_mode)
The fan mode is set to Both.
Definition: climate_mode.h:74
ClimatePreset
Enum for all preset modes.
Definition: climate_mode.h:82
const std::set< ClimateSwingMode > & get_supported_swing_modes() const
std::set< climate::ClimateMode > supported_modes_
void set_visual_max_humidity(float visual_max_humidity)
void set_supports_target_humidity(bool supports_target_humidity)
The fan mode is set to Middle.
Definition: climate_mode.h:60
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_auto(bool supported)
void set_supports_current_humidity(bool supports_current_humidity)
This class contains all static data for climate devices.
void add_supported_custom_preset(const std::string &preset)
void set_visual_min_temperature(float visual_min_temperature)
The climate device is set to heat to reach the target temperature.
Definition: climate_mode.h:18
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_cool_mode(bool supports_cool_mode)
void add_supported_custom_fan_mode(const std::string &mode)
void set_visual_target_temperature_step(float temperature_step)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_medium(bool supported)
void set_visual_current_temperature_step(float temperature_step)
int8_t get_current_temperature_accuracy_decimals() const
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_high(bool supported)
The fan mode is set to Diffuse.
Definition: climate_mode.h:64
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_middle(bool supported)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_off(bool supported)
The climate device is set to dry/humidity mode.
Definition: climate_mode.h:22
void set_fan_mode_support_(climate::ClimateFanMode mode, bool supported)
std::set< climate::ClimatePreset > supported_presets_
const std::set< std::string > & get_supported_custom_fan_modes() const
void set_supported_presets(std::set< ClimatePreset > presets)
const std::set< ClimateFanMode > & get_supported_fan_modes() const
bool get_supports_current_humidity() const
ClimateSwingMode swing_mode
Definition: climate.h:581
ClimateSwingMode
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:70
const std::set< std::string > & get_supported_custom_presets() const
std::set< climate::ClimateFanMode > supported_fan_modes_
bool supports_custom_preset(const std::string &custom_preset) const
std::set< std::string > supported_custom_presets_
void add_supported_preset(ClimatePreset preset)
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_low(bool supported)
bool supports_custom_fan_mode(const std::string &custom_fan_mode) const
float get_visual_current_temperature_step() const
void add_supported_swing_mode(ClimateSwingMode mode)
The fan mode is set to Horizontal.
Definition: climate_mode.h:78
The climate device is set to cool to reach the target temperature.
Definition: climate_mode.h:16
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_focus(bool supported)
void set_supported_fan_modes(std::set< ClimateFanMode > modes)
The fan mode is set to Auto.
Definition: climate_mode.h:52
bool supports_preset(ClimatePreset preset) const
const std::set< ClimateMode > & get_supported_modes() const
uint8_t custom_preset
Definition: climate.h:579
const std::set< climate::ClimatePreset > & get_supported_presets() const
void set_supported_modes(std::set< ClimateMode > modes)
float get_visual_target_temperature_step() const
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:183
The climate device is adjusting the temperatre dynamically.
Definition: climate_mode.h:27
int8_t get_target_temperature_accuracy_decimals() const
void set_visual_max_temperature(float visual_max_temperature)
ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20") void set_supports_swing_mode_off(bool supported)
The climate device is set to heat/cool to reach the target temperature.
Definition: climate_mode.h:14
The fan mode is set to Vertical.
Definition: climate_mode.h:76
The fan mode is set to Focus.
Definition: climate_mode.h:62
The fan mode is set to Off.
Definition: climate_mode.h:50
void add_supported_fan_mode(ClimateFanMode mode)
void set_mode_support_(climate::ClimateMode mode, bool supported)
void set_swing_mode_support_(climate::ClimateSwingMode mode, bool supported)
The fan mode is set to High.
Definition: climate_mode.h:58
ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20") void set_supports_swing_mode_both(bool supported)
ClimateMode
Enum for all modes a climate device can be in.
Definition: climate_mode.h:10
The swing mode is set to Off.
Definition: climate_mode.h:72
The climate device is off.
Definition: climate_mode.h:12
ClimateFanMode fan_mode
Definition: climate.h:573
void set_supports_action(bool supports_action)
bool supports_fan_mode(ClimateFanMode fan_mode) const
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_on(bool supported)
bool get_supports_current_temperature() const
The fan mode is set to On.
Definition: climate_mode.h:48
std::set< std::string > supported_custom_fan_modes_
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_heat_mode(bool supports_heat_mode)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool supports_swing_mode(ClimateSwingMode swing_mode) const
void set_supported_swing_modes(std::set< ClimateSwingMode > modes)
void set_supports_two_point_target_temperature(bool supports_two_point_target_temperature)
void set_supports_current_temperature(bool supports_current_temperature)
void set_supported_custom_fan_modes(std::set< std::string > supported_custom_fan_modes)
The fan mode is set to Medium.
Definition: climate_mode.h:56
bool get_supports_two_point_target_temperature() const
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_fan_only_mode(bool supports_fan_only_mode)
The climate device only has the fan enabled, no heating or cooling is taking place.
Definition: climate_mode.h:20
ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20") void set_supports_swing_mode_horizontal(bool supported)
uint8_t custom_fan_mode
Definition: climate.h:574
void add_supported_mode(ClimateMode mode)
ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20") void set_supports_swing_mode_vertical(bool supported)
ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20") void set_supports_auto_mode(bool supports_auto_mode)
ClimatePreset preset
Definition: climate.h:578
ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20") void set_supports_fan_mode_diffuse(bool supported)
bool supports_mode(ClimateMode mode) const