ESPHome  2023.3.1
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  ESP_LOGD(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
11  this->validate_();
12  if (this->mode_.has_value()) {
13  const LogString *mode_s = climate_mode_to_string(*this->mode_);
14  ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(mode_s));
15  }
16  if (this->custom_fan_mode_.has_value()) {
17  this->fan_mode_.reset();
18  ESP_LOGD(TAG, " Custom Fan: %s", this->custom_fan_mode_.value().c_str());
19  }
20  if (this->fan_mode_.has_value()) {
21  this->custom_fan_mode_.reset();
22  const LogString *fan_mode_s = climate_fan_mode_to_string(*this->fan_mode_);
23  ESP_LOGD(TAG, " Fan: %s", LOG_STR_ARG(fan_mode_s));
24  }
25  if (this->custom_preset_.has_value()) {
26  this->preset_.reset();
27  ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset_.value().c_str());
28  }
29  if (this->preset_.has_value()) {
30  this->custom_preset_.reset();
31  const LogString *preset_s = climate_preset_to_string(*this->preset_);
32  ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(preset_s));
33  }
34  if (this->swing_mode_.has_value()) {
35  const LogString *swing_mode_s = climate_swing_mode_to_string(*this->swing_mode_);
36  ESP_LOGD(TAG, " Swing: %s", LOG_STR_ARG(swing_mode_s));
37  }
38  if (this->target_temperature_.has_value()) {
39  ESP_LOGD(TAG, " Target Temperature: %.2f", *this->target_temperature_);
40  }
41  if (this->target_temperature_low_.has_value()) {
42  ESP_LOGD(TAG, " Target Temperature Low: %.2f", *this->target_temperature_low_);
43  }
44  if (this->target_temperature_high_.has_value()) {
45  ESP_LOGD(TAG, " Target Temperature High: %.2f", *this->target_temperature_high_);
46  }
47  this->parent_->control_callback_.call();
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 {
217  if (this->parent_->get_traits().supports_custom_preset(preset)) {
218  this->custom_preset_ = preset;
219  this->preset_.reset();
220  } else {
221  ESP_LOGW(TAG, "'%s' - Unrecognized preset %s", this->parent_->get_name().c_str(), preset.c_str());
222  }
223  }
224  return *this;
225 }
227  if (preset.has_value()) {
228  this->set_preset(preset.value());
229  }
230  return *this;
231 }
233  this->swing_mode_ = swing_mode;
234  return *this;
235 }
237  if (str_equals_case_insensitive(swing_mode, "OFF")) {
239  } else if (str_equals_case_insensitive(swing_mode, "BOTH")) {
241  } else if (str_equals_case_insensitive(swing_mode, "VERTICAL")) {
243  } else if (str_equals_case_insensitive(swing_mode, "HORIZONTAL")) {
245  } else {
246  ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %s", this->parent_->get_name().c_str(), swing_mode.c_str());
247  }
248  return *this;
249 }
250 
253  return *this;
254 }
257  return *this;
258 }
261  return *this;
262 }
263 const optional<ClimateMode> &ClimateCall::get_mode() const { return this->mode_; }
267 optional<bool> ClimateCall::get_away() const {
268  if (!this->preset_.has_value())
269  return {};
271 }
277 ClimateCall &ClimateCall::set_away(bool away) {
279  return *this;
280 }
281 ClimateCall &ClimateCall::set_away(optional<bool> away) {
282  if (away.has_value())
284  return *this;
285 }
288  return *this;
289 }
292  return *this;
293 }
296  return *this;
297 }
299  this->mode_ = mode;
300  return *this;
301 }
303  this->fan_mode_ = fan_mode;
304  this->custom_fan_mode_.reset();
305  return *this;
306 }
308  this->preset_ = preset;
309  this->custom_preset_.reset();
310  return *this;
311 }
313  this->swing_mode_ = swing_mode;
314  return *this;
315 }
316 
317 void Climate::add_on_state_callback(std::function<void()> &&callback) {
318  this->state_callback_.add(std::move(callback));
319 }
320 
321 void Climate::add_on_control_callback(std::function<void()> &&callback) {
322  this->control_callback_.add(std::move(callback));
323 }
324 
325 // Random 32bit value; If this changes existing restore preferences are invalidated
326 static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;
327 
329  this->rtc_ = global_preferences->make_preference<ClimateDeviceRestoreState>(this->get_object_id_hash() ^
330  RESTORE_STATE_VERSION);
331  ClimateDeviceRestoreState recovered{};
332  if (!this->rtc_.load(&recovered))
333  return {};
334  return recovered;
335 }
337 #if (defined(USE_ESP_IDF) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \
338  !defined(CLANG_TIDY)
339 #pragma GCC diagnostic ignored "-Wclass-memaccess"
340 #define TEMP_IGNORE_MEMACCESS
341 #endif
343  // initialize as zero to prevent random data on stack triggering erase
344  memset(&state, 0, sizeof(ClimateDeviceRestoreState));
345 #ifdef TEMP_IGNORE_MEMACCESS
346 #pragma GCC diagnostic pop
347 #undef TEMP_IGNORE_MEMACCESS
348 #endif
349 
350  state.mode = this->mode;
351  auto traits = this->get_traits();
352  if (traits.get_supports_two_point_target_temperature()) {
353  state.target_temperature_low = this->target_temperature_low;
354  state.target_temperature_high = this->target_temperature_high;
355  } else {
356  state.target_temperature = this->target_temperature;
357  }
358  if (traits.get_supports_fan_modes() && fan_mode.has_value()) {
359  state.uses_custom_fan_mode = false;
360  state.fan_mode = this->fan_mode.value();
361  }
362  if (!traits.get_supported_custom_fan_modes().empty() && custom_fan_mode.has_value()) {
363  state.uses_custom_fan_mode = true;
364  const auto &supported = traits.get_supported_custom_fan_modes();
365  std::vector<std::string> vec{supported.begin(), supported.end()};
366  auto it = std::find(vec.begin(), vec.end(), custom_fan_mode);
367  if (it != vec.end()) {
368  state.custom_fan_mode = std::distance(vec.begin(), it);
369  }
370  }
371  if (traits.get_supports_presets() && preset.has_value()) {
372  state.uses_custom_preset = false;
373  state.preset = this->preset.value();
374  }
375  if (!traits.get_supported_custom_presets().empty() && custom_preset.has_value()) {
376  state.uses_custom_preset = true;
377  const auto &supported = traits.get_supported_custom_presets();
378  std::vector<std::string> vec{supported.begin(), supported.end()};
379  auto it = std::find(vec.begin(), vec.end(), custom_preset);
380  // only set custom preset if value exists, otherwise leave it as is
381  if (it != vec.cend()) {
382  state.custom_preset = std::distance(vec.begin(), it);
383  }
384  }
385  if (traits.get_supports_swing_modes()) {
386  state.swing_mode = this->swing_mode;
387  }
388 
389  this->rtc_.save(&state);
390 }
392  ESP_LOGD(TAG, "'%s' - Sending state:", this->name_.c_str());
393  auto traits = this->get_traits();
394 
395  ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(climate_mode_to_string(this->mode)));
396  if (traits.get_supports_action()) {
397  ESP_LOGD(TAG, " Action: %s", LOG_STR_ARG(climate_action_to_string(this->action)));
398  }
399  if (traits.get_supports_fan_modes() && this->fan_mode.has_value()) {
400  ESP_LOGD(TAG, " Fan Mode: %s", LOG_STR_ARG(climate_fan_mode_to_string(this->fan_mode.value())));
401  }
402  if (!traits.get_supported_custom_fan_modes().empty() && this->custom_fan_mode.has_value()) {
403  ESP_LOGD(TAG, " Custom Fan Mode: %s", this->custom_fan_mode.value().c_str());
404  }
405  if (traits.get_supports_presets() && this->preset.has_value()) {
406  ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(climate_preset_to_string(this->preset.value())));
407  }
408  if (!traits.get_supported_custom_presets().empty() && this->custom_preset.has_value()) {
409  ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset.value().c_str());
410  }
411  if (traits.get_supports_swing_modes()) {
412  ESP_LOGD(TAG, " Swing Mode: %s", LOG_STR_ARG(climate_swing_mode_to_string(this->swing_mode)));
413  }
414  if (traits.get_supports_current_temperature()) {
415  ESP_LOGD(TAG, " Current Temperature: %.2f°C", this->current_temperature);
416  }
417  if (traits.get_supports_two_point_target_temperature()) {
418  ESP_LOGD(TAG, " Target Temperature: Low: %.2f°C High: %.2f°C", this->target_temperature_low,
420  } else {
421  ESP_LOGD(TAG, " Target Temperature: %.2f°C", this->target_temperature);
422  }
423 
424  // Send state to frontend
425  this->state_callback_.call();
426  // Save state
427  this->save_state_();
428 }
429 
431  auto traits = this->traits();
432  if (this->visual_min_temperature_override_.has_value()) {
433  traits.set_visual_min_temperature(*this->visual_min_temperature_override_);
434  }
435  if (this->visual_max_temperature_override_.has_value()) {
436  traits.set_visual_max_temperature(*this->visual_max_temperature_override_);
437  }
438  if (this->visual_target_temperature_step_override_.has_value()) {
439  traits.set_visual_target_temperature_step(*this->visual_target_temperature_step_override_);
440  traits.set_visual_current_temperature_step(*this->visual_current_temperature_step_override_);
441  }
442 
443  return traits;
444 }
445 
446 void Climate::set_visual_min_temperature_override(float visual_min_temperature_override) {
447  this->visual_min_temperature_override_ = visual_min_temperature_override;
448 }
449 void Climate::set_visual_max_temperature_override(float visual_max_temperature_override) {
450  this->visual_max_temperature_override_ = visual_max_temperature_override;
451 }
452 void Climate::set_visual_temperature_step_override(float target, float current) {
453  this->visual_target_temperature_step_override_ = target;
454  this->visual_current_temperature_step_override_ = current;
455 }
456 #pragma GCC diagnostic push
457 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
458 Climate::Climate(const std::string &name) : EntityBase(name) {}
459 #pragma GCC diagnostic pop
460 
463 
465  auto call = climate->make_call();
466  auto traits = climate->get_traits();
467  call.set_mode(this->mode);
469  call.set_target_temperature_low(this->target_temperature_low);
470  call.set_target_temperature_high(this->target_temperature_high);
471  } else {
472  call.set_target_temperature(this->target_temperature);
473  }
475  call.set_fan_mode(this->fan_mode);
476  }
478  call.set_preset(this->preset);
479  }
481  call.set_swing_mode(this->swing_mode);
482  }
483  return call;
484 }
486  auto traits = climate->get_traits();
487  climate->mode = this->mode;
491  } else {
492  climate->target_temperature = this->target_temperature;
493  }
495  climate->fan_mode = this->fan_mode;
496  }
498  // std::set has consistent order (lexicographic for strings), so this is ok
499  const auto &modes = traits.get_supported_custom_fan_modes();
500  std::vector<std::string> modes_vec{modes.begin(), modes.end()};
501  if (custom_fan_mode < modes_vec.size()) {
502  climate->custom_fan_mode = modes_vec[this->custom_fan_mode];
503  }
504  }
506  climate->preset = this->preset;
507  }
509  // std::set has consistent order (lexicographic for strings), so this is ok
510  const auto &presets = traits.get_supported_custom_presets();
511  std::vector<std::string> presets_vec{presets.begin(), presets.end()};
512  if (custom_preset < presets_vec.size()) {
513  climate->custom_preset = presets_vec[this->custom_preset];
514  }
515  }
517  climate->swing_mode = this->swing_mode;
518  }
519  climate->publish_state();
520 }
521 
522 template<typename T1, typename T2> bool set_alternative(optional<T1> &dst, optional<T2> &alt, const T1 &src) {
523  bool is_changed = alt.has_value();
524  alt.reset();
525  if (is_changed || dst != src) {
526  dst = src;
527  is_changed = true;
528  }
529  return is_changed;
530 }
531 
533  return set_alternative(this->fan_mode, this->custom_fan_mode, mode);
534 }
535 
536 bool Climate::set_custom_fan_mode_(const std::string &mode) {
537  return set_alternative(this->custom_fan_mode, this->fan_mode, mode);
538 }
539 
540 bool Climate::set_preset_(ClimatePreset preset) { return set_alternative(this->preset, this->custom_preset, preset); }
541 
542 bool Climate::set_custom_preset_(const std::string &preset) {
543  return set_alternative(this->custom_preset, this->preset, preset);
544 }
545 
546 void Climate::dump_traits_(const char *tag) {
547  auto traits = this->get_traits();
548  ESP_LOGCONFIG(tag, "ClimateTraits:");
549  ESP_LOGCONFIG(tag, " [x] Visual settings:");
550  ESP_LOGCONFIG(tag, " - Min: %.1f", traits.get_visual_min_temperature());
551  ESP_LOGCONFIG(tag, " - Max: %.1f", traits.get_visual_max_temperature());
552  ESP_LOGCONFIG(tag, " - Step:");
553  ESP_LOGCONFIG(tag, " Target: %.1f", traits.get_visual_target_temperature_step());
554  ESP_LOGCONFIG(tag, " Current: %.1f", traits.get_visual_current_temperature_step());
556  ESP_LOGCONFIG(tag, " [x] Supports current temperature");
557  }
559  ESP_LOGCONFIG(tag, " [x] Supports two-point target temperature");
560  }
561  if (traits.get_supports_action()) {
562  ESP_LOGCONFIG(tag, " [x] Supports action");
563  }
564  if (!traits.get_supported_modes().empty()) {
565  ESP_LOGCONFIG(tag, " [x] Supported modes:");
567  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_mode_to_string(m)));
568  }
569  if (!traits.get_supported_fan_modes().empty()) {
570  ESP_LOGCONFIG(tag, " [x] Supported fan modes:");
572  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_fan_mode_to_string(m)));
573  }
574  if (!traits.get_supported_custom_fan_modes().empty()) {
575  ESP_LOGCONFIG(tag, " [x] Supported custom fan modes:");
576  for (const std::string &s : traits.get_supported_custom_fan_modes())
577  ESP_LOGCONFIG(tag, " - %s", s.c_str());
578  }
579  if (!traits.get_supported_presets().empty()) {
580  ESP_LOGCONFIG(tag, " [x] Supported presets:");
582  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_preset_to_string(p)));
583  }
584  if (!traits.get_supported_custom_presets().empty()) {
585  ESP_LOGCONFIG(tag, " [x] Supported custom presets:");
586  for (const std::string &s : traits.get_supported_custom_presets())
587  ESP_LOGCONFIG(tag, " - %s", s.c_str());
588  }
589  if (!traits.get_supported_swing_modes().empty()) {
590  ESP_LOGCONFIG(tag, " [x] Supported swing modes:");
592  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_swing_mode_to_string(m)));
593  }
594 }
595 
596 } // namespace climate
597 } // 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:204
float target_temperature_low
Definition: climate.h:562
const char * name
Definition: stm32flash.h:78
optional< std::string > custom_preset_
Definition: climate.h:120
The fan mode is set to Both.
Definition: climate_mode.h:74
ClimatePreset
Enum for all preset modes.
Definition: climate_mode.h:82
CallbackManager< void()> control_callback_
Definition: climate.h:296
float target_temperature
The target temperature of the climate device.
Definition: climate.h:183
Device is in home preset.
Definition: climate_mode.h:86
const optional< ClimateMode > & get_mode() const
Definition: climate.cpp:263
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 LogString * climate_mode_to_string(ClimateMode mode)
Convert the given ClimateMode to a human-readable string.
Definition: climate_mode.cpp:6
std::set< ClimateSwingMode > get_supported_swing_modes() const
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:461
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:522
optional< ClimateFanMode > fan_mode_
Definition: climate.h:116
const optional< float > & get_target_temperature_low() const
Definition: climate.cpp:265
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:563
bool uses_custom_fan_mode
Definition: climate.h:548
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:232
ClimateSwingMode swing_mode
Definition: climate.h:558
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
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:317
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:207
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:485
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition: climate.cpp:255
void add_on_control_callback(std::function< void()> &&callback)
Add a callback for the climate device configuration; each time the configuration parameters of a clim...
Definition: climate.cpp:321
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:462
Device is in comfort preset.
Definition: climate_mode.h:92
float get_visual_current_temperature_step() const
const optional< std::string > & get_custom_preset() const
Definition: climate.cpp:275
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition: climate.cpp:251
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:117
Device is reacting to activity (e.g., movement sensors)
Definition: climate_mode.h:98
const optional< ClimatePreset > & get_preset() const
Definition: climate.cpp:274
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:556
const std::set< climate::ClimatePreset > & get_supported_presets() const
ESPPreferences * global_preferences
optional< ClimatePreset > preset_
Definition: climate.h:119
float get_visual_target_temperature_step() const
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: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:430
std::set< ClimateMode > get_supported_modes() const
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:449
The fan mode is set to Focus.
Definition: climate_mode.h:62
const optional< std::string > & get_custom_fan_mode() const
Definition: climate.cpp:273
void set_visual_min_temperature_override(float visual_min_temperature_override)
Definition: climate.cpp:446
The fan mode is set to Off.
Definition: climate_mode.h:50
const optional< float > & get_target_temperature() const
Definition: climate.cpp:264
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:391
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:536
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:550
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:259
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
void set_visual_temperature_step_override(float target, float current)
Definition: climate.cpp:452
const optional< ClimateFanMode > & get_fan_mode() const
Definition: climate.cpp:272
Device is in boost preset.
Definition: climate_mode.h:90
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: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:542
bool uses_custom_preset
Definition: climate.h:553
const optional< ClimateSwingMode > & get_swing_mode() const
Definition: climate.cpp:276
void save_state_()
Internal method to save the state of the climate device to recover memory.
Definition: climate.cpp:336
Definition: a4988.cpp:4
optional< ClimateMode > mode_
Definition: climate.h:112
void dump_traits_(const char *tag)
Definition: climate.cpp:546
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:328
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:266
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:540
uint8_t custom_fan_mode
Definition: climate.h:551
optional< float > target_temperature_low_
Definition: climate.h:114
float target_temperature
Definition: climate.h:560
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
Definition: climate.cpp:464
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition: climate.h:186
std::set< ClimateFanMode > get_supported_fan_modes() const
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
Definition: climate.cpp:532
ClimatePreset preset
Definition: climate.h:555
ClimateDevice - This is the base class for all climate integrations.
Definition: climate.h:167
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:135
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.