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