ESPHome  2021.11.3
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_two_point_target_temperature(bool supports_two_point_target_temperature) {
49  supports_two_point_target_temperature_ = supports_two_point_target_temperature;
50  }
51  void set_supported_modes(std::set<ClimateMode> modes) { supported_modes_ = std::move(modes); }
53  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
54  void set_supports_auto_mode(bool supports_auto_mode) { set_mode_support_(CLIMATE_MODE_AUTO, supports_auto_mode); }
55  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
56  void set_supports_cool_mode(bool supports_cool_mode) { set_mode_support_(CLIMATE_MODE_COOL, supports_cool_mode); }
57  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
58  void set_supports_heat_mode(bool supports_heat_mode) { set_mode_support_(CLIMATE_MODE_HEAT, supports_heat_mode); }
59  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
60  void set_supports_heat_cool_mode(bool supported) { set_mode_support_(CLIMATE_MODE_HEAT_COOL, supported); }
61  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
62  void set_supports_fan_only_mode(bool supports_fan_only_mode) {
63  set_mode_support_(CLIMATE_MODE_FAN_ONLY, supports_fan_only_mode);
64  }
65  ESPDEPRECATED("This method is deprecated, use set_supported_modes() instead", "v1.20")
66  void set_supports_dry_mode(bool supports_dry_mode) { set_mode_support_(CLIMATE_MODE_DRY, supports_dry_mode); }
67  bool supports_mode(ClimateMode mode) const { return supported_modes_.count(mode); }
68  const std::set<ClimateMode> get_supported_modes() const { return supported_modes_; }
69 
70  void set_supports_action(bool supports_action) { supports_action_ = supports_action; }
71  bool get_supports_action() const { return supports_action_; }
72 
73  void set_supported_fan_modes(std::set<ClimateFanMode> modes) { supported_fan_modes_ = std::move(modes); }
75  void add_supported_custom_fan_mode(const std::string &mode) { supported_custom_fan_modes_.insert(mode); }
76  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
77  void set_supports_fan_mode_on(bool supported) { set_fan_mode_support_(CLIMATE_FAN_ON, supported); }
78  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
79  void set_supports_fan_mode_off(bool supported) { set_fan_mode_support_(CLIMATE_FAN_OFF, supported); }
80  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
81  void set_supports_fan_mode_auto(bool supported) { set_fan_mode_support_(CLIMATE_FAN_AUTO, supported); }
82  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
83  void set_supports_fan_mode_low(bool supported) { set_fan_mode_support_(CLIMATE_FAN_LOW, supported); }
84  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
85  void set_supports_fan_mode_medium(bool supported) { set_fan_mode_support_(CLIMATE_FAN_MEDIUM, supported); }
86  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
87  void set_supports_fan_mode_high(bool supported) { set_fan_mode_support_(CLIMATE_FAN_HIGH, supported); }
88  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
89  void set_supports_fan_mode_middle(bool supported) { set_fan_mode_support_(CLIMATE_FAN_MIDDLE, supported); }
90  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
91  void set_supports_fan_mode_focus(bool supported) { set_fan_mode_support_(CLIMATE_FAN_FOCUS, supported); }
92  ESPDEPRECATED("This method is deprecated, use set_supported_fan_modes() instead", "v1.20")
93  void set_supports_fan_mode_diffuse(bool supported) { set_fan_mode_support_(CLIMATE_FAN_DIFFUSE, supported); }
94  bool supports_fan_mode(ClimateFanMode fan_mode) const { return supported_fan_modes_.count(fan_mode); }
95  bool get_supports_fan_modes() const { return !supported_fan_modes_.empty() || !supported_custom_fan_modes_.empty(); }
96  const std::set<ClimateFanMode> get_supported_fan_modes() const { return supported_fan_modes_; }
97 
98  void set_supported_custom_fan_modes(std::set<std::string> supported_custom_fan_modes) {
99  supported_custom_fan_modes_ = std::move(supported_custom_fan_modes);
100  }
101  const std::set<std::string> &get_supported_custom_fan_modes() const { return supported_custom_fan_modes_; }
102  bool supports_custom_fan_mode(const std::string &custom_fan_mode) const {
103  return supported_custom_fan_modes_.count(custom_fan_mode);
104  }
105 
106  void set_supported_presets(std::set<ClimatePreset> presets) { supported_presets_ = std::move(presets); }
108  void add_supported_custom_preset(const std::string &preset) { supported_custom_presets_.insert(preset); }
109  bool supports_preset(ClimatePreset preset) const { return supported_presets_.count(preset); }
110  bool get_supports_presets() const { return !supported_presets_.empty(); }
111  const std::set<climate::ClimatePreset> &get_supported_presets() const { return supported_presets_; }
112 
113  void set_supported_custom_presets(std::set<std::string> supported_custom_presets) {
114  supported_custom_presets_ = std::move(supported_custom_presets);
115  }
116  const std::set<std::string> &get_supported_custom_presets() const { return supported_custom_presets_; }
117  bool supports_custom_preset(const std::string &custom_preset) const {
118  return supported_custom_presets_.count(custom_preset);
119  }
120  ESPDEPRECATED("This method is deprecated, use set_supported_presets() instead", "v1.20")
121  void set_supports_away(bool supports) {
122  if (supports) {
125  }
126  }
127  ESPDEPRECATED("This method is deprecated, use supports_preset() instead", "v1.20")
128  bool get_supports_away() const { return supports_preset(CLIMATE_PRESET_AWAY); }
129 
130  void set_supported_swing_modes(std::set<ClimateSwingMode> modes) { supported_swing_modes_ = std::move(modes); }
132  ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
133  void set_supports_swing_mode_off(bool supported) { set_swing_mode_support_(CLIMATE_SWING_OFF, supported); }
134  ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
135  void set_supports_swing_mode_both(bool supported) { set_swing_mode_support_(CLIMATE_SWING_BOTH, supported); }
136  ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
137  void set_supports_swing_mode_vertical(bool supported) { set_swing_mode_support_(CLIMATE_SWING_VERTICAL, supported); }
138  ESPDEPRECATED("This method is deprecated, use set_supported_swing_modes() instead", "v1.20")
139  void set_supports_swing_mode_horizontal(bool supported) {
141  }
142  bool supports_swing_mode(ClimateSwingMode swing_mode) const { return supported_swing_modes_.count(swing_mode); }
143  bool get_supports_swing_modes() const { return !supported_swing_modes_.empty(); }
144  const std::set<ClimateSwingMode> get_supported_swing_modes() { return supported_swing_modes_; }
145 
147  void set_visual_min_temperature(float visual_min_temperature) { visual_min_temperature_ = visual_min_temperature; }
149  void set_visual_max_temperature(float visual_max_temperature) { visual_max_temperature_ = visual_max_temperature; }
151  int8_t get_temperature_accuracy_decimals() const;
152  void set_visual_temperature_step(float temperature_step) { visual_temperature_step_ = temperature_step; }
153 
154  protected:
156  if (supported) {
157  supported_modes_.insert(mode);
158  } else {
159  supported_modes_.erase(mode);
160  }
161  }
163  if (supported) {
164  supported_fan_modes_.insert(mode);
165  } else {
166  supported_fan_modes_.erase(mode);
167  }
168  }
170  if (supported) {
171  supported_swing_modes_.insert(mode);
172  } else {
173  supported_swing_modes_.erase(mode);
174  }
175  }
176 
179  std::set<climate::ClimateMode> supported_modes_ = {climate::CLIMATE_MODE_OFF};
180  bool supports_action_{false};
181  std::set<climate::ClimateFanMode> supported_fan_modes_;
182  std::set<climate::ClimateSwingMode> supported_swing_modes_;
183  std::set<climate::ClimatePreset> supported_presets_;
184  std::set<std::string> supported_custom_fan_modes_;
185  std::set<std::string> supported_custom_presets_;
186 
190 };
191 
192 } // namespace climate
193 } // 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)
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:72
ClimatePreset
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:80
std::set< climate::ClimateMode > supported_modes_
Device is in home preset.
Definition: climate_mode.h:84
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)
This class contains all static data for climate devices.
const std::set< ClimateFanMode > get_supported_fan_modes() const
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
int8_t get_temperature_accuracy_decimals() const
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)
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_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)
ESPDEPRECATED("This method is deprecated, use set_supported_presets() instead", "v1.20") void set_supports_away(bool supports)
ClimateSwingMode swing_mode
Definition: climate.h:545
ClimateSwingMode
Enum for all modes a climate swing can be in.
Definition: climate_mode.h:68
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)
Device is in away preset.
Definition: climate_mode.h:86
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
void add_supported_swing_mode(ClimateSwingMode mode)
The fan mode is set to Horizontal.
Definition: climate_mode.h:76
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
uint8_t custom_preset
Definition: climate.h:543
const std::set< climate::ClimatePreset > & get_supported_presets() const
void set_supported_modes(std::set< ClimateMode > modes)
The climate device is adjusting the temperatre dynamically.
Definition: climate_mode.h:27
const std::set< ClimateMode > get_supported_modes() 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:74
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:70
The climate device is off.
Definition: climate_mode.h:12
ClimateFanMode fan_mode
Definition: climate.h:537
void set_supports_action(bool supports_action)
ESPDEPRECATED("This method is deprecated, use supports_preset() instead", "v1.20") bool get_supports_away() const
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
ClimateMode mode
Definition: climate.h:534
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)
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
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:538
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)
const std::set< ClimateSwingMode > get_supported_swing_modes()
ClimatePreset preset
Definition: climate.h:542
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