ESPHome  2021.10.2
climate.cpp
Go to the documentation of this file.
1 #include "climate.h"
2 
3 namespace esphome {
4 namespace climate {
5 
6 static const char *const TAG = "climate";
7 
9  ESP_LOGD(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
10  this->validate_();
11  if (this->mode_.has_value()) {
12  const LogString *mode_s = climate_mode_to_string(*this->mode_);
13  ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(mode_s));
14  }
15  if (this->custom_fan_mode_.has_value()) {
16  this->fan_mode_.reset();
17  ESP_LOGD(TAG, " Custom Fan: %s", this->custom_fan_mode_.value().c_str());
18  }
19  if (this->fan_mode_.has_value()) {
20  this->custom_fan_mode_.reset();
21  const LogString *fan_mode_s = climate_fan_mode_to_string(*this->fan_mode_);
22  ESP_LOGD(TAG, " Fan: %s", LOG_STR_ARG(fan_mode_s));
23  }
24  if (this->custom_preset_.has_value()) {
25  this->preset_.reset();
26  ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset_.value().c_str());
27  }
28  if (this->preset_.has_value()) {
29  this->custom_preset_.reset();
30  const LogString *preset_s = climate_preset_to_string(*this->preset_);
31  ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(preset_s));
32  }
33  if (this->swing_mode_.has_value()) {
34  const LogString *swing_mode_s = climate_swing_mode_to_string(*this->swing_mode_);
35  ESP_LOGD(TAG, " Swing: %s", LOG_STR_ARG(swing_mode_s));
36  }
37  if (this->target_temperature_.has_value()) {
38  ESP_LOGD(TAG, " Target Temperature: %.2f", *this->target_temperature_);
39  }
40  if (this->target_temperature_low_.has_value()) {
41  ESP_LOGD(TAG, " Target Temperature Low: %.2f", *this->target_temperature_low_);
42  }
43  if (this->target_temperature_high_.has_value()) {
44  ESP_LOGD(TAG, " Target Temperature High: %.2f", *this->target_temperature_high_);
45  }
46  this->parent_->control(*this);
47 }
49  auto traits = this->parent_->get_traits();
50  if (this->mode_.has_value()) {
51  auto mode = *this->mode_;
52  if (!traits.supports_mode(mode)) {
53  ESP_LOGW(TAG, " Mode %s is not supported by this device!", LOG_STR_ARG(climate_mode_to_string(mode)));
54  this->mode_.reset();
55  }
56  }
57  if (this->custom_fan_mode_.has_value()) {
58  auto custom_fan_mode = *this->custom_fan_mode_;
59  if (!traits.supports_custom_fan_mode(custom_fan_mode)) {
60  ESP_LOGW(TAG, " Fan Mode %s is not supported by this device!", custom_fan_mode.c_str());
61  this->custom_fan_mode_.reset();
62  }
63  } else if (this->fan_mode_.has_value()) {
64  auto fan_mode = *this->fan_mode_;
65  if (!traits.supports_fan_mode(fan_mode)) {
66  ESP_LOGW(TAG, " Fan Mode %s is not supported by this device!",
67  LOG_STR_ARG(climate_fan_mode_to_string(fan_mode)));
68  this->fan_mode_.reset();
69  }
70  }
71  if (this->custom_preset_.has_value()) {
72  auto custom_preset = *this->custom_preset_;
73  if (!traits.supports_custom_preset(custom_preset)) {
74  ESP_LOGW(TAG, " Preset %s is not supported by this device!", custom_preset.c_str());
75  this->custom_preset_.reset();
76  }
77  } else if (this->preset_.has_value()) {
78  auto preset = *this->preset_;
79  if (!traits.supports_preset(preset)) {
80  ESP_LOGW(TAG, " Preset %s is not supported by this device!", LOG_STR_ARG(climate_preset_to_string(preset)));
81  this->preset_.reset();
82  }
83  }
84  if (this->swing_mode_.has_value()) {
85  auto swing_mode = *this->swing_mode_;
86  if (!traits.supports_swing_mode(swing_mode)) {
87  ESP_LOGW(TAG, " Swing Mode %s is not supported by this device!",
89  this->swing_mode_.reset();
90  }
91  }
92  if (this->target_temperature_.has_value()) {
93  auto target = *this->target_temperature_;
94  if (traits.get_supports_two_point_target_temperature()) {
95  ESP_LOGW(TAG, " Cannot set target temperature for climate device "
96  "with two-point target temperature!");
97  this->target_temperature_.reset();
98  } else if (std::isnan(target)) {
99  ESP_LOGW(TAG, " Target temperature must not be NAN!");
100  this->target_temperature_.reset();
101  }
102  }
104  if (!traits.get_supports_two_point_target_temperature()) {
105  ESP_LOGW(TAG, " Cannot set low/high target temperature for this device!");
108  }
109  }
110  if (this->target_temperature_low_.has_value() && std::isnan(*this->target_temperature_low_)) {
111  ESP_LOGW(TAG, " Target temperature low must not be NAN!");
113  }
114  if (this->target_temperature_high_.has_value() && std::isnan(*this->target_temperature_high_)) {
115  ESP_LOGW(TAG, " Target temperature low must not be NAN!");
117  }
119  float low = *this->target_temperature_low_;
120  float high = *this->target_temperature_high_;
121  if (low > high) {
122  ESP_LOGW(TAG, " Target temperature low %.2f must be smaller than target temperature high %.2f!", low, high);
125  }
126  }
127 }
129  this->mode_ = mode;
130  return *this;
131 }
132 ClimateCall &ClimateCall::set_mode(const std::string &mode) {
133  if (str_equals_case_insensitive(mode, "OFF")) {
134  this->set_mode(CLIMATE_MODE_OFF);
135  } else if (str_equals_case_insensitive(mode, "AUTO")) {
137  } else if (str_equals_case_insensitive(mode, "COOL")) {
139  } else if (str_equals_case_insensitive(mode, "HEAT")) {
141  } else if (str_equals_case_insensitive(mode, "FAN_ONLY")) {
143  } else if (str_equals_case_insensitive(mode, "DRY")) {
144  this->set_mode(CLIMATE_MODE_DRY);
145  } else if (str_equals_case_insensitive(mode, "HEAT_COOL")) {
147  } else {
148  ESP_LOGW(TAG, "'%s' - Unrecognized mode %s", this->parent_->get_name().c_str(), mode.c_str());
149  }
150  return *this;
151 }
153  this->fan_mode_ = fan_mode;
154  this->custom_fan_mode_.reset();
155  return *this;
156 }
158  if (str_equals_case_insensitive(fan_mode, "ON")) {
160  } else if (str_equals_case_insensitive(fan_mode, "OFF")) {
162  } else if (str_equals_case_insensitive(fan_mode, "AUTO")) {
164  } else if (str_equals_case_insensitive(fan_mode, "LOW")) {
166  } else if (str_equals_case_insensitive(fan_mode, "MEDIUM")) {
168  } else if (str_equals_case_insensitive(fan_mode, "HIGH")) {
170  } else if (str_equals_case_insensitive(fan_mode, "MIDDLE")) {
172  } else if (str_equals_case_insensitive(fan_mode, "FOCUS")) {
174  } else if (str_equals_case_insensitive(fan_mode, "DIFFUSE")) {
176  } else {
177  if (this->parent_->get_traits().supports_custom_fan_mode(fan_mode)) {
178  this->custom_fan_mode_ = fan_mode;
179  this->fan_mode_.reset();
180  } else {
181  ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %s", this->parent_->get_name().c_str(), fan_mode.c_str());
182  }
183  }
184  return *this;
185 }
187  if (fan_mode.has_value()) {
188  this->set_fan_mode(fan_mode.value());
189  }
190  return *this;
191 }
193  this->preset_ = preset;
194  this->custom_preset_.reset();
195  return *this;
196 }
198  if (str_equals_case_insensitive(preset, "ECO")) {
200  } else if (str_equals_case_insensitive(preset, "AWAY")) {
202  } else if (str_equals_case_insensitive(preset, "BOOST")) {
204  } else if (str_equals_case_insensitive(preset, "COMFORT")) {
206  } else if (str_equals_case_insensitive(preset, "HOME")) {
208  } else if (str_equals_case_insensitive(preset, "SLEEP")) {
210  } else if (str_equals_case_insensitive(preset, "ACTIVITY")) {
212  } else {
213  if (this->parent_->get_traits().supports_custom_preset(preset)) {
214  this->custom_preset_ = preset;
215  this->preset_.reset();
216  } else {
217  ESP_LOGW(TAG, "'%s' - Unrecognized preset %s", this->parent_->get_name().c_str(), preset.c_str());
218  }
219  }
220  return *this;
221 }
223  if (preset.has_value()) {
224  this->set_preset(preset.value());
225  }
226  return *this;
227 }
229  this->swing_mode_ = swing_mode;
230  return *this;
231 }
233  if (str_equals_case_insensitive(swing_mode, "OFF")) {
235  } else if (str_equals_case_insensitive(swing_mode, "BOTH")) {
237  } else if (str_equals_case_insensitive(swing_mode, "VERTICAL")) {
239  } else if (str_equals_case_insensitive(swing_mode, "HORIZONTAL")) {
241  } else {
242  ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %s", this->parent_->get_name().c_str(), swing_mode.c_str());
243  }
244  return *this;
245 }
246 
249  return *this;
250 }
253  return *this;
254 }
257  return *this;
258 }
259 const optional<ClimateMode> &ClimateCall::get_mode() const { return this->mode_; }
263 optional<bool> ClimateCall::get_away() const {
264  if (!this->preset_.has_value())
265  return {};
267 }
273 ClimateCall &ClimateCall::set_away(bool away) {
275  return *this;
276 }
277 ClimateCall &ClimateCall::set_away(optional<bool> away) {
278  if (away.has_value())
280  return *this;
281 }
284  return *this;
285 }
288  return *this;
289 }
292  return *this;
293 }
295  this->mode_ = mode;
296  return *this;
297 }
299  this->fan_mode_ = fan_mode;
300  this->custom_fan_mode_.reset();
301  return *this;
302 }
304  this->preset_ = preset;
305  this->custom_preset_.reset();
306  return *this;
307 }
309  this->swing_mode_ = swing_mode;
310  return *this;
311 }
312 
313 void Climate::add_on_state_callback(std::function<void()> &&callback) {
314  this->state_callback_.add(std::move(callback));
315 }
316 
317 // Random 32bit value; If this changes existing restore preferences are invalidated
318 static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;
319 
321  this->rtc_ = global_preferences->make_preference<ClimateDeviceRestoreState>(this->get_object_id_hash() ^
322  RESTORE_STATE_VERSION);
323  ClimateDeviceRestoreState recovered{};
324  if (!this->rtc_.load(&recovered))
325  return {};
326  return recovered;
327 }
329 #if defined(USE_ESP_IDF) && !defined(CLANG_TIDY)
330 #pragma GCC diagnostic ignored "-Wclass-memaccess"
331 #endif
333  // initialize as zero to prevent random data on stack triggering erase
334  memset(&state, 0, sizeof(ClimateDeviceRestoreState));
335 #if USE_ESP_IDF && !defined(CLANG_TIDY)
336 #pragma GCC diagnostic pop
337 #endif
338 
339  state.mode = this->mode;
340  auto traits = this->get_traits();
341  if (traits.get_supports_two_point_target_temperature()) {
342  state.target_temperature_low = this->target_temperature_low;
343  state.target_temperature_high = this->target_temperature_high;
344  } else {
345  state.target_temperature = this->target_temperature;
346  }
347  if (traits.get_supports_fan_modes() && fan_mode.has_value()) {
348  state.uses_custom_fan_mode = false;
349  state.fan_mode = this->fan_mode.value();
350  }
351  if (!traits.get_supported_custom_fan_modes().empty() && custom_fan_mode.has_value()) {
352  state.uses_custom_fan_mode = true;
353  const auto &supported = traits.get_supported_custom_fan_modes();
354  std::vector<std::string> vec{supported.begin(), supported.end()};
355  auto it = std::find(vec.begin(), vec.end(), custom_fan_mode);
356  if (it != vec.end()) {
357  state.custom_fan_mode = std::distance(vec.begin(), it);
358  }
359  }
360  if (traits.get_supports_presets() && preset.has_value()) {
361  state.uses_custom_preset = false;
362  state.preset = this->preset.value();
363  }
364  if (!traits.get_supported_custom_presets().empty() && custom_preset.has_value()) {
365  state.uses_custom_preset = true;
366  const auto &supported = traits.get_supported_custom_presets();
367  std::vector<std::string> vec{supported.begin(), supported.end()};
368  auto it = std::find(vec.begin(), vec.end(), custom_preset);
369  // only set custom preset if value exists, otherwise leave it as is
370  if (it != vec.cend()) {
371  state.custom_preset = std::distance(vec.begin(), it);
372  }
373  }
374  if (traits.get_supports_swing_modes()) {
375  state.swing_mode = this->swing_mode;
376  }
377 
378  this->rtc_.save(&state);
379 }
381  ESP_LOGD(TAG, "'%s' - Sending state:", this->name_.c_str());
382  auto traits = this->get_traits();
383 
384  ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(climate_mode_to_string(this->mode)));
385  if (traits.get_supports_action()) {
386  ESP_LOGD(TAG, " Action: %s", LOG_STR_ARG(climate_action_to_string(this->action)));
387  }
388  if (traits.get_supports_fan_modes() && this->fan_mode.has_value()) {
389  ESP_LOGD(TAG, " Fan Mode: %s", LOG_STR_ARG(climate_fan_mode_to_string(this->fan_mode.value())));
390  }
391  if (!traits.get_supported_custom_fan_modes().empty() && this->custom_fan_mode.has_value()) {
392  ESP_LOGD(TAG, " Custom Fan Mode: %s", this->custom_fan_mode.value().c_str());
393  }
394  if (traits.get_supports_presets() && this->preset.has_value()) {
395  ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(climate_preset_to_string(this->preset.value())));
396  }
397  if (!traits.get_supported_custom_presets().empty() && this->custom_preset.has_value()) {
398  ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset.value().c_str());
399  }
400  if (traits.get_supports_swing_modes()) {
401  ESP_LOGD(TAG, " Swing Mode: %s", LOG_STR_ARG(climate_swing_mode_to_string(this->swing_mode)));
402  }
403  if (traits.get_supports_current_temperature()) {
404  ESP_LOGD(TAG, " Current Temperature: %.2f°C", this->current_temperature);
405  }
406  if (traits.get_supports_two_point_target_temperature()) {
407  ESP_LOGD(TAG, " Target Temperature: Low: %.2f°C High: %.2f°C", this->target_temperature_low,
409  } else {
410  ESP_LOGD(TAG, " Target Temperature: %.2f°C", this->target_temperature);
411  }
412 
413  // Send state to frontend
414  this->state_callback_.call();
415  // Save state
416  this->save_state_();
417 }
418 uint32_t Climate::hash_base() { return 3104134496UL; }
419 
421  auto traits = this->traits();
422  if (this->visual_min_temperature_override_.has_value()) {
423  traits.set_visual_min_temperature(*this->visual_min_temperature_override_);
424  }
425  if (this->visual_max_temperature_override_.has_value()) {
426  traits.set_visual_max_temperature(*this->visual_max_temperature_override_);
427  }
428  if (this->visual_temperature_step_override_.has_value()) {
429  traits.set_visual_temperature_step(*this->visual_temperature_step_override_);
430  }
431  return traits;
432 }
433 
434 void Climate::set_visual_min_temperature_override(float visual_min_temperature_override) {
435  this->visual_min_temperature_override_ = visual_min_temperature_override;
436 }
437 void Climate::set_visual_max_temperature_override(float visual_max_temperature_override) {
438  this->visual_max_temperature_override_ = visual_max_temperature_override;
439 }
440 void Climate::set_visual_temperature_step_override(float visual_temperature_step_override) {
441  this->visual_temperature_step_override_ = visual_temperature_step_override;
442 }
443 #pragma GCC diagnostic push
444 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
445 Climate::Climate(const std::string &name) : EntityBase(name) {}
446 #pragma GCC diagnostic pop
447 
450 
452  auto call = climate->make_call();
453  auto traits = climate->get_traits();
454  call.set_mode(this->mode);
456  call.set_target_temperature_low(this->target_temperature_low);
457  call.set_target_temperature_high(this->target_temperature_high);
458  } else {
459  call.set_target_temperature(this->target_temperature);
460  }
462  call.set_fan_mode(this->fan_mode);
463  }
465  call.set_preset(this->preset);
466  }
468  call.set_swing_mode(this->swing_mode);
469  }
470  return call;
471 }
473  auto traits = climate->get_traits();
474  climate->mode = this->mode;
478  } else {
479  climate->target_temperature = this->target_temperature;
480  }
482  climate->fan_mode = this->fan_mode;
483  }
485  // std::set has consistent order (lexicographic for strings), so this is ok
486  const auto &modes = traits.get_supported_custom_fan_modes();
487  std::vector<std::string> modes_vec{modes.begin(), modes.end()};
488  if (custom_fan_mode < modes_vec.size()) {
489  climate->custom_fan_mode = modes_vec[this->custom_fan_mode];
490  }
491  }
493  climate->preset = this->preset;
494  }
496  // std::set has consistent order (lexicographic for strings), so this is ok
497  const auto &presets = traits.get_supported_custom_presets();
498  std::vector<std::string> presets_vec{presets.begin(), presets.end()};
499  if (custom_preset < presets_vec.size()) {
500  climate->custom_preset = presets_vec[this->custom_preset];
501  }
502  }
504  climate->swing_mode = this->swing_mode;
505  }
506  climate->publish_state();
507 }
508 
509 template<typename T1, typename T2> bool set_alternative(optional<T1> &dst, optional<T2> &alt, const T1 &src) {
510  bool is_changed = alt.has_value();
511  alt.reset();
512  if (is_changed || dst != src) {
513  dst = src;
514  is_changed = true;
515  }
516  return is_changed;
517 }
518 
520  return set_alternative(this->fan_mode, this->custom_fan_mode, mode);
521 }
522 
523 bool Climate::set_custom_fan_mode_(const std::string &mode) {
524  return set_alternative(this->custom_fan_mode, this->fan_mode, mode);
525 }
526 
527 bool Climate::set_preset_(ClimatePreset preset) { return set_alternative(this->preset, this->custom_preset, preset); }
528 
529 bool Climate::set_custom_preset_(const std::string &preset) {
530  return set_alternative(this->custom_preset, this->preset, preset);
531 }
532 
533 void Climate::dump_traits_(const char *tag) {
534  auto traits = this->get_traits();
535  ESP_LOGCONFIG(tag, "ClimateTraits:");
536  ESP_LOGCONFIG(tag, " [x] Visual settings:");
537  ESP_LOGCONFIG(tag, " - Min: %.1f", traits.get_visual_min_temperature());
538  ESP_LOGCONFIG(tag, " - Max: %.1f", traits.get_visual_max_temperature());
539  ESP_LOGCONFIG(tag, " - Step: %.1f", traits.get_visual_temperature_step());
541  ESP_LOGCONFIG(tag, " [x] Supports current temperature");
543  ESP_LOGCONFIG(tag, " [x] Supports two-point target temperature");
545  ESP_LOGCONFIG(tag, " [x] Supports action");
546  if (!traits.get_supported_modes().empty()) {
547  ESP_LOGCONFIG(tag, " [x] Supported modes:");
549  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_mode_to_string(m)));
550  }
551  if (!traits.get_supported_fan_modes().empty()) {
552  ESP_LOGCONFIG(tag, " [x] Supported fan modes:");
554  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_fan_mode_to_string(m)));
555  }
556  if (!traits.get_supported_custom_fan_modes().empty()) {
557  ESP_LOGCONFIG(tag, " [x] Supported custom fan modes:");
558  for (const std::string &s : traits.get_supported_custom_fan_modes())
559  ESP_LOGCONFIG(tag, " - %s", s.c_str());
560  }
561  if (!traits.get_supported_presets().empty()) {
562  ESP_LOGCONFIG(tag, " [x] Supported presets:");
564  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_preset_to_string(p)));
565  }
566  if (!traits.get_supported_custom_presets().empty()) {
567  ESP_LOGCONFIG(tag, " [x] Supported custom presets:");
568  for (const std::string &s : traits.get_supported_custom_presets())
569  ESP_LOGCONFIG(tag, " - %s", s.c_str());
570  }
571  if (!traits.get_supported_swing_modes().empty()) {
572  ESP_LOGCONFIG(tag, " [x] Supported swing modes:");
574  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_swing_mode_to_string(m)));
575  }
576 }
577 
578 } // namespace climate
579 } // namespace esphome
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
The fan mode is set to Low.
Definition: climate_mode.h:54
uint32_t hash_base() override
Definition: climate.cpp:418
value_type const & value() const
Definition: optional.h:89
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition: climate.h:204
float target_temperature_low
Definition: climate.h:549
void set_visual_temperature_step_override(float visual_temperature_step_override)
Definition: climate.cpp:440
optional< std::string > custom_preset_
Definition: climate.h:120
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
float target_temperature
The target temperature of the climate device.
Definition: climate.h:183
Device is in home preset.
Definition: climate_mode.h:84
const optional< ClimateMode > & get_mode() const
Definition: climate.cpp:259
optional< float > target_temperature_
Definition: climate.h:113
The fan mode is set to Middle.
Definition: climate_mode.h:60
This class contains all static data for climate devices.
const std::set< ClimateFanMode > get_supported_fan_modes() const
const LogString * climate_mode_to_string(ClimateMode mode)
Convert the given ClimateMode to a human-readable string.
Definition: climate_mode.cpp:6
The climate device is set to heat to reach the target temperature.
Definition: climate_mode.h:18
Struct used to save the state of the climate device in restore memory.
Definition: climate.h:125
Climate()
Construct a climate device with empty name (will be set later).
Definition: climate.cpp:448
ClimateMode mode
The active mode of the climate device.
Definition: climate.h:175
bool set_alternative(optional< T1 > &dst, optional< T2 > &alt, const T1 &src)
Definition: climate.cpp:509
optional< ClimateFanMode > fan_mode_
Definition: climate.h:116
const optional< float > & get_target_temperature_low() const
Definition: climate.cpp:261
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition: climate.h:188
The fan mode is set to Diffuse.
Definition: climate_mode.h:64
const std::string & get_name() const
Definition: entity_base.cpp:11
optional< float > target_temperature_high_
Definition: climate.h:115
bool has_value() const
Definition: optional.h:87
The climate device is set to dry/humidity mode.
Definition: climate_mode.h:22
float target_temperature_high
Definition: climate.h:550
bool uses_custom_fan_mode
Definition: climate.h:535
const std::set< std::string > & get_supported_custom_fan_modes() const
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition: climate.cpp:228
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
void add_on_state_callback(std::function< void()> &&callback)
Add a callback for the climate device state, each time the state of the climate device is updated (us...
Definition: climate.cpp:313
bool supports_custom_preset(const std::string &custom_preset) const
Device is prepared for sleep.
Definition: climate_mode.h:94
optional< std::string > custom_fan_mode
The active custom fan mode of the climate device.
Definition: climate.h:207
Device is in away preset.
Definition: climate_mode.h:86
bool supports_custom_fan_mode(const std::string &custom_fan_mode) const
void apply(Climate *climate)
Apply these settings to the climate device.
Definition: climate.cpp:472
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition: climate.cpp:251
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition: climate.cpp:449
Device is in comfort preset.
Definition: climate_mode.h:90
const optional< std::string > & get_custom_preset() const
Definition: climate.cpp:271
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition: climate.cpp:247
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
optional< ClimateSwingMode > swing_mode_
Definition: climate.h:117
Device is reacting to activity (e.g., movement sensors)
Definition: climate_mode.h:96
const optional< ClimatePreset > & get_preset() const
Definition: climate.cpp:270
The fan mode is set to Auto.
Definition: climate_mode.h:52
optional< ClimatePreset > preset
The active preset of the climate device.
Definition: climate.h:210
uint8_t custom_preset
Definition: climate.h:543
const std::set< climate::ClimatePreset > & get_supported_presets() const
ESPPreferences * global_preferences
optional< ClimatePreset > preset_
Definition: climate.h:119
virtual ClimateTraits traits()=0
Get the default traits of this climate device.
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition: climate.cpp:192
virtual void control(const ClimateCall &call)=0
Control the climate device, this is a virtual method that each climate integration must implement...
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition: climate.cpp:152
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition: climate.cpp:420
const LogString * climate_preset_to_string(ClimatePreset preset)
Convert the given ClimateSwingMode to a human-readable string.
The climate device is adjusting the temperatre dynamically.
Definition: climate_mode.h:27
const std::set< ClimateMode > get_supported_modes() const
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
void set_visual_max_temperature_override(float visual_max_temperature_override)
Definition: climate.cpp:437
The fan mode is set to Focus.
Definition: climate_mode.h:62
const optional< std::string > & get_custom_fan_mode() const
Definition: climate.cpp:269
void set_visual_min_temperature_override(float visual_min_temperature_override)
Definition: climate.cpp:434
The fan mode is set to Off.
Definition: climate_mode.h:50
const optional< float > & get_target_temperature() const
Definition: climate.cpp:260
optional< std::string > custom_fan_mode_
Definition: climate.h:118
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition: climate.cpp:380
bool set_custom_fan_mode_(const std::string &mode)
Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed.
Definition: climate.cpp:523
The fan mode is set to High.
Definition: climate_mode.h:58
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
optional< std::string > custom_preset
The active custom preset mode of the climate device.
Definition: climate.h:213
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition: climate.cpp:255
const LogString * climate_fan_mode_to_string(ClimateFanMode fan_mode)
Convert the given ClimateFanMode to a human-readable string.
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition: climate.h:198
const optional< ClimateFanMode > & get_fan_mode() const
Definition: climate.cpp:268
Device is in boost preset.
Definition: climate_mode.h:88
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
bool get_supports_current_temperature() const
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
Definition: climate.cpp:128
The fan mode is set to On.
Definition: climate_mode.h:48
bool set_custom_preset_(const std::string &preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
Definition: climate.cpp:529
ClimateMode mode
Definition: climate.h:534
bool uses_custom_preset
Definition: climate.h:540
const optional< ClimateSwingMode > & get_swing_mode() const
Definition: climate.cpp:272
void save_state_()
Internal method to save the state of the climate device to recover memory.
Definition: climate.cpp:328
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
optional< ClimateMode > mode_
Definition: climate.h:112
void dump_traits_(const char *tag)
Definition: climate.cpp:533
Device is running an energy-saving preset.
Definition: climate_mode.h:92
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition: climate.cpp:320
The fan mode is set to Medium.
Definition: climate_mode.h:56
bool get_supports_two_point_target_temperature() const
const optional< float > & get_target_temperature_high() const
Definition: climate.cpp:262
The climate device only has the fan enabled, no heating or cooling is taking place.
Definition: climate_mode.h:20
const LogString * climate_action_to_string(ClimateAction action)
Convert the given ClimateAction to a human-readable string.
bool set_preset_(ClimatePreset preset)
Set preset. Reset custom preset. Return true if preset has been changed.
Definition: climate.cpp:527
uint8_t custom_fan_mode
Definition: climate.h:538
optional< float > target_temperature_low_
Definition: climate.h:114
float target_temperature
Definition: climate.h:547
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
Definition: climate.cpp:451
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition: climate.h:186
const std::set< ClimateSwingMode > get_supported_swing_modes()
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
Definition: climate.cpp:519
ClimatePreset preset
Definition: climate.h:542
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167
bool str_equals_case_insensitive(const std::string &a, const std::string &b)
Compare string a to string b (ignoring case) and return whether they are equal.
Definition: helpers.cpp:330
Climate *const parent_
Definition: climate.h:111
const LogString * climate_swing_mode_to_string(ClimateSwingMode swing_mode)
Convert the given ClimateSwingMode to a human-readable string.