ESPHome  2022.6.2
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(*this);
48 }
50  auto traits = this->parent_->get_traits();
51  if (this->mode_.has_value()) {
52  auto mode = *this->mode_;
53  if (!traits.supports_mode(mode)) {
54  ESP_LOGW(TAG, " Mode %s is not supported by this device!", LOG_STR_ARG(climate_mode_to_string(mode)));
55  this->mode_.reset();
56  }
57  }
58  if (this->custom_fan_mode_.has_value()) {
59  auto custom_fan_mode = *this->custom_fan_mode_;
60  if (!traits.supports_custom_fan_mode(custom_fan_mode)) {
61  ESP_LOGW(TAG, " Fan Mode %s is not supported by this device!", custom_fan_mode.c_str());
62  this->custom_fan_mode_.reset();
63  }
64  } else if (this->fan_mode_.has_value()) {
65  auto fan_mode = *this->fan_mode_;
66  if (!traits.supports_fan_mode(fan_mode)) {
67  ESP_LOGW(TAG, " Fan Mode %s is not supported by this device!",
68  LOG_STR_ARG(climate_fan_mode_to_string(fan_mode)));
69  this->fan_mode_.reset();
70  }
71  }
72  if (this->custom_preset_.has_value()) {
73  auto custom_preset = *this->custom_preset_;
74  if (!traits.supports_custom_preset(custom_preset)) {
75  ESP_LOGW(TAG, " Preset %s is not supported by this device!", custom_preset.c_str());
76  this->custom_preset_.reset();
77  }
78  } else if (this->preset_.has_value()) {
79  auto preset = *this->preset_;
80  if (!traits.supports_preset(preset)) {
81  ESP_LOGW(TAG, " Preset %s is not supported by this device!", LOG_STR_ARG(climate_preset_to_string(preset)));
82  this->preset_.reset();
83  }
84  }
85  if (this->swing_mode_.has_value()) {
86  auto swing_mode = *this->swing_mode_;
87  if (!traits.supports_swing_mode(swing_mode)) {
88  ESP_LOGW(TAG, " Swing Mode %s is not supported by this device!",
90  this->swing_mode_.reset();
91  }
92  }
93  if (this->target_temperature_.has_value()) {
94  auto target = *this->target_temperature_;
95  if (traits.get_supports_two_point_target_temperature()) {
96  ESP_LOGW(TAG, " Cannot set target temperature for climate device "
97  "with two-point target temperature!");
98  this->target_temperature_.reset();
99  } else if (std::isnan(target)) {
100  ESP_LOGW(TAG, " Target temperature must not be NAN!");
101  this->target_temperature_.reset();
102  }
103  }
105  if (!traits.get_supports_two_point_target_temperature()) {
106  ESP_LOGW(TAG, " Cannot set low/high target temperature for this device!");
109  }
110  }
111  if (this->target_temperature_low_.has_value() && std::isnan(*this->target_temperature_low_)) {
112  ESP_LOGW(TAG, " Target temperature low must not be NAN!");
114  }
115  if (this->target_temperature_high_.has_value() && std::isnan(*this->target_temperature_high_)) {
116  ESP_LOGW(TAG, " Target temperature low must not be NAN!");
118  }
120  float low = *this->target_temperature_low_;
121  float high = *this->target_temperature_high_;
122  if (low > high) {
123  ESP_LOGW(TAG, " Target temperature low %.2f must be smaller than target temperature high %.2f!", low, high);
126  }
127  }
128 }
130  this->mode_ = mode;
131  return *this;
132 }
133 ClimateCall &ClimateCall::set_mode(const std::string &mode) {
134  if (str_equals_case_insensitive(mode, "OFF")) {
135  this->set_mode(CLIMATE_MODE_OFF);
136  } else if (str_equals_case_insensitive(mode, "AUTO")) {
138  } else if (str_equals_case_insensitive(mode, "COOL")) {
140  } else if (str_equals_case_insensitive(mode, "HEAT")) {
142  } else if (str_equals_case_insensitive(mode, "FAN_ONLY")) {
144  } else if (str_equals_case_insensitive(mode, "DRY")) {
145  this->set_mode(CLIMATE_MODE_DRY);
146  } else if (str_equals_case_insensitive(mode, "HEAT_COOL")) {
148  } else {
149  ESP_LOGW(TAG, "'%s' - Unrecognized mode %s", this->parent_->get_name().c_str(), mode.c_str());
150  }
151  return *this;
152 }
154  this->fan_mode_ = fan_mode;
155  this->custom_fan_mode_.reset();
156  return *this;
157 }
159  if (str_equals_case_insensitive(fan_mode, "ON")) {
161  } else if (str_equals_case_insensitive(fan_mode, "OFF")) {
163  } else if (str_equals_case_insensitive(fan_mode, "AUTO")) {
165  } else if (str_equals_case_insensitive(fan_mode, "LOW")) {
167  } else if (str_equals_case_insensitive(fan_mode, "MEDIUM")) {
169  } else if (str_equals_case_insensitive(fan_mode, "HIGH")) {
171  } else if (str_equals_case_insensitive(fan_mode, "MIDDLE")) {
173  } else if (str_equals_case_insensitive(fan_mode, "FOCUS")) {
175  } else if (str_equals_case_insensitive(fan_mode, "DIFFUSE")) {
177  } else {
178  if (this->parent_->get_traits().supports_custom_fan_mode(fan_mode)) {
179  this->custom_fan_mode_ = fan_mode;
180  this->fan_mode_.reset();
181  } else {
182  ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %s", this->parent_->get_name().c_str(), fan_mode.c_str());
183  }
184  }
185  return *this;
186 }
188  if (fan_mode.has_value()) {
189  this->set_fan_mode(fan_mode.value());
190  }
191  return *this;
192 }
194  this->preset_ = preset;
195  this->custom_preset_.reset();
196  return *this;
197 }
199  if (str_equals_case_insensitive(preset, "ECO")) {
201  } else if (str_equals_case_insensitive(preset, "AWAY")) {
203  } else if (str_equals_case_insensitive(preset, "BOOST")) {
205  } else if (str_equals_case_insensitive(preset, "COMFORT")) {
207  } else if (str_equals_case_insensitive(preset, "HOME")) {
209  } else if (str_equals_case_insensitive(preset, "SLEEP")) {
211  } else if (str_equals_case_insensitive(preset, "ACTIVITY")) {
213  } else {
214  if (this->parent_->get_traits().supports_custom_preset(preset)) {
215  this->custom_preset_ = preset;
216  this->preset_.reset();
217  } else {
218  ESP_LOGW(TAG, "'%s' - Unrecognized preset %s", this->parent_->get_name().c_str(), preset.c_str());
219  }
220  }
221  return *this;
222 }
224  if (preset.has_value()) {
225  this->set_preset(preset.value());
226  }
227  return *this;
228 }
230  this->swing_mode_ = swing_mode;
231  return *this;
232 }
234  if (str_equals_case_insensitive(swing_mode, "OFF")) {
236  } else if (str_equals_case_insensitive(swing_mode, "BOTH")) {
238  } else if (str_equals_case_insensitive(swing_mode, "VERTICAL")) {
240  } else if (str_equals_case_insensitive(swing_mode, "HORIZONTAL")) {
242  } else {
243  ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %s", this->parent_->get_name().c_str(), swing_mode.c_str());
244  }
245  return *this;
246 }
247 
250  return *this;
251 }
254  return *this;
255 }
258  return *this;
259 }
260 const optional<ClimateMode> &ClimateCall::get_mode() const { return this->mode_; }
264 optional<bool> ClimateCall::get_away() const {
265  if (!this->preset_.has_value())
266  return {};
268 }
274 ClimateCall &ClimateCall::set_away(bool away) {
276  return *this;
277 }
278 ClimateCall &ClimateCall::set_away(optional<bool> away) {
279  if (away.has_value())
281  return *this;
282 }
285  return *this;
286 }
289  return *this;
290 }
293  return *this;
294 }
296  this->mode_ = mode;
297  return *this;
298 }
300  this->fan_mode_ = fan_mode;
301  this->custom_fan_mode_.reset();
302  return *this;
303 }
305  this->preset_ = preset;
306  this->custom_preset_.reset();
307  return *this;
308 }
310  this->swing_mode_ = swing_mode;
311  return *this;
312 }
313 
314 void Climate::add_on_state_callback(std::function<void()> &&callback) {
315  this->state_callback_.add(std::move(callback));
316 }
317 
318 // Random 32bit value; If this changes existing restore preferences are invalidated
319 static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;
320 
322  this->rtc_ = global_preferences->make_preference<ClimateDeviceRestoreState>(this->get_object_id_hash() ^
323  RESTORE_STATE_VERSION);
324  ClimateDeviceRestoreState recovered{};
325  if (!this->rtc_.load(&recovered))
326  return {};
327  return recovered;
328 }
330 #if (defined(USE_ESP_IDF) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \
331  !defined(CLANG_TIDY)
332 #pragma GCC diagnostic ignored "-Wclass-memaccess"
333 #define TEMP_IGNORE_MEMACCESS
334 #endif
336  // initialize as zero to prevent random data on stack triggering erase
337  memset(&state, 0, sizeof(ClimateDeviceRestoreState));
338 #ifdef TEMP_IGNORE_MEMACCESS
339 #pragma GCC diagnostic pop
340 #undef TEMP_IGNORE_MEMACCESS
341 #endif
342 
343  state.mode = this->mode;
344  auto traits = this->get_traits();
345  if (traits.get_supports_two_point_target_temperature()) {
346  state.target_temperature_low = this->target_temperature_low;
347  state.target_temperature_high = this->target_temperature_high;
348  } else {
349  state.target_temperature = this->target_temperature;
350  }
351  if (traits.get_supports_fan_modes() && fan_mode.has_value()) {
352  state.uses_custom_fan_mode = false;
353  state.fan_mode = this->fan_mode.value();
354  }
355  if (!traits.get_supported_custom_fan_modes().empty() && custom_fan_mode.has_value()) {
356  state.uses_custom_fan_mode = true;
357  const auto &supported = traits.get_supported_custom_fan_modes();
358  std::vector<std::string> vec{supported.begin(), supported.end()};
359  auto it = std::find(vec.begin(), vec.end(), custom_fan_mode);
360  if (it != vec.end()) {
361  state.custom_fan_mode = std::distance(vec.begin(), it);
362  }
363  }
364  if (traits.get_supports_presets() && preset.has_value()) {
365  state.uses_custom_preset = false;
366  state.preset = this->preset.value();
367  }
368  if (!traits.get_supported_custom_presets().empty() && custom_preset.has_value()) {
369  state.uses_custom_preset = true;
370  const auto &supported = traits.get_supported_custom_presets();
371  std::vector<std::string> vec{supported.begin(), supported.end()};
372  auto it = std::find(vec.begin(), vec.end(), custom_preset);
373  // only set custom preset if value exists, otherwise leave it as is
374  if (it != vec.cend()) {
375  state.custom_preset = std::distance(vec.begin(), it);
376  }
377  }
378  if (traits.get_supports_swing_modes()) {
379  state.swing_mode = this->swing_mode;
380  }
381 
382  this->rtc_.save(&state);
383 }
385  ESP_LOGD(TAG, "'%s' - Sending state:", this->name_.c_str());
386  auto traits = this->get_traits();
387 
388  ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(climate_mode_to_string(this->mode)));
389  if (traits.get_supports_action()) {
390  ESP_LOGD(TAG, " Action: %s", LOG_STR_ARG(climate_action_to_string(this->action)));
391  }
392  if (traits.get_supports_fan_modes() && this->fan_mode.has_value()) {
393  ESP_LOGD(TAG, " Fan Mode: %s", LOG_STR_ARG(climate_fan_mode_to_string(this->fan_mode.value())));
394  }
395  if (!traits.get_supported_custom_fan_modes().empty() && this->custom_fan_mode.has_value()) {
396  ESP_LOGD(TAG, " Custom Fan Mode: %s", this->custom_fan_mode.value().c_str());
397  }
398  if (traits.get_supports_presets() && this->preset.has_value()) {
399  ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(climate_preset_to_string(this->preset.value())));
400  }
401  if (!traits.get_supported_custom_presets().empty() && this->custom_preset.has_value()) {
402  ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset.value().c_str());
403  }
404  if (traits.get_supports_swing_modes()) {
405  ESP_LOGD(TAG, " Swing Mode: %s", LOG_STR_ARG(climate_swing_mode_to_string(this->swing_mode)));
406  }
407  if (traits.get_supports_current_temperature()) {
408  ESP_LOGD(TAG, " Current Temperature: %.2f°C", this->current_temperature);
409  }
410  if (traits.get_supports_two_point_target_temperature()) {
411  ESP_LOGD(TAG, " Target Temperature: Low: %.2f°C High: %.2f°C", this->target_temperature_low,
413  } else {
414  ESP_LOGD(TAG, " Target Temperature: %.2f°C", this->target_temperature);
415  }
416 
417  // Send state to frontend
418  this->state_callback_.call();
419  // Save state
420  this->save_state_();
421 }
422 
424  auto traits = this->traits();
425  if (this->visual_min_temperature_override_.has_value()) {
426  traits.set_visual_min_temperature(*this->visual_min_temperature_override_);
427  }
428  if (this->visual_max_temperature_override_.has_value()) {
429  traits.set_visual_max_temperature(*this->visual_max_temperature_override_);
430  }
431  if (this->visual_temperature_step_override_.has_value()) {
432  traits.set_visual_temperature_step(*this->visual_temperature_step_override_);
433  }
434  return traits;
435 }
436 
437 void Climate::set_visual_min_temperature_override(float visual_min_temperature_override) {
438  this->visual_min_temperature_override_ = visual_min_temperature_override;
439 }
440 void Climate::set_visual_max_temperature_override(float visual_max_temperature_override) {
441  this->visual_max_temperature_override_ = visual_max_temperature_override;
442 }
443 void Climate::set_visual_temperature_step_override(float visual_temperature_step_override) {
444  this->visual_temperature_step_override_ = visual_temperature_step_override;
445 }
446 #pragma GCC diagnostic push
447 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
448 Climate::Climate(const std::string &name) : EntityBase(name) {}
449 #pragma GCC diagnostic pop
450 
453 
455  auto call = climate->make_call();
456  auto traits = climate->get_traits();
457  call.set_mode(this->mode);
459  call.set_target_temperature_low(this->target_temperature_low);
460  call.set_target_temperature_high(this->target_temperature_high);
461  } else {
462  call.set_target_temperature(this->target_temperature);
463  }
465  call.set_fan_mode(this->fan_mode);
466  }
468  call.set_preset(this->preset);
469  }
471  call.set_swing_mode(this->swing_mode);
472  }
473  return call;
474 }
476  auto traits = climate->get_traits();
477  climate->mode = this->mode;
481  } else {
482  climate->target_temperature = this->target_temperature;
483  }
485  climate->fan_mode = this->fan_mode;
486  }
488  // std::set has consistent order (lexicographic for strings), so this is ok
489  const auto &modes = traits.get_supported_custom_fan_modes();
490  std::vector<std::string> modes_vec{modes.begin(), modes.end()};
491  if (custom_fan_mode < modes_vec.size()) {
492  climate->custom_fan_mode = modes_vec[this->custom_fan_mode];
493  }
494  }
496  climate->preset = this->preset;
497  }
499  // std::set has consistent order (lexicographic for strings), so this is ok
500  const auto &presets = traits.get_supported_custom_presets();
501  std::vector<std::string> presets_vec{presets.begin(), presets.end()};
502  if (custom_preset < presets_vec.size()) {
503  climate->custom_preset = presets_vec[this->custom_preset];
504  }
505  }
507  climate->swing_mode = this->swing_mode;
508  }
509  climate->publish_state();
510 }
511 
512 template<typename T1, typename T2> bool set_alternative(optional<T1> &dst, optional<T2> &alt, const T1 &src) {
513  bool is_changed = alt.has_value();
514  alt.reset();
515  if (is_changed || dst != src) {
516  dst = src;
517  is_changed = true;
518  }
519  return is_changed;
520 }
521 
523  return set_alternative(this->fan_mode, this->custom_fan_mode, mode);
524 }
525 
526 bool Climate::set_custom_fan_mode_(const std::string &mode) {
527  return set_alternative(this->custom_fan_mode, this->fan_mode, mode);
528 }
529 
530 bool Climate::set_preset_(ClimatePreset preset) { return set_alternative(this->preset, this->custom_preset, preset); }
531 
532 bool Climate::set_custom_preset_(const std::string &preset) {
533  return set_alternative(this->custom_preset, this->preset, preset);
534 }
535 
536 void Climate::dump_traits_(const char *tag) {
537  auto traits = this->get_traits();
538  ESP_LOGCONFIG(tag, "ClimateTraits:");
539  ESP_LOGCONFIG(tag, " [x] Visual settings:");
540  ESP_LOGCONFIG(tag, " - Min: %.1f", traits.get_visual_min_temperature());
541  ESP_LOGCONFIG(tag, " - Max: %.1f", traits.get_visual_max_temperature());
542  ESP_LOGCONFIG(tag, " - Step: %.1f", traits.get_visual_temperature_step());
544  ESP_LOGCONFIG(tag, " [x] Supports current temperature");
546  ESP_LOGCONFIG(tag, " [x] Supports two-point target temperature");
548  ESP_LOGCONFIG(tag, " [x] Supports action");
549  if (!traits.get_supported_modes().empty()) {
550  ESP_LOGCONFIG(tag, " [x] Supported modes:");
552  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_mode_to_string(m)));
553  }
554  if (!traits.get_supported_fan_modes().empty()) {
555  ESP_LOGCONFIG(tag, " [x] Supported fan modes:");
557  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_fan_mode_to_string(m)));
558  }
559  if (!traits.get_supported_custom_fan_modes().empty()) {
560  ESP_LOGCONFIG(tag, " [x] Supported custom fan modes:");
561  for (const std::string &s : traits.get_supported_custom_fan_modes())
562  ESP_LOGCONFIG(tag, " - %s", s.c_str());
563  }
564  if (!traits.get_supported_presets().empty()) {
565  ESP_LOGCONFIG(tag, " [x] Supported presets:");
567  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_preset_to_string(p)));
568  }
569  if (!traits.get_supported_custom_presets().empty()) {
570  ESP_LOGCONFIG(tag, " [x] Supported custom presets:");
571  for (const std::string &s : traits.get_supported_custom_presets())
572  ESP_LOGCONFIG(tag, " - %s", s.c_str());
573  }
574  if (!traits.get_supported_swing_modes().empty()) {
575  ESP_LOGCONFIG(tag, " [x] Supported swing modes:");
577  ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_swing_mode_to_string(m)));
578  }
579 }
580 
581 } // namespace climate
582 } // 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
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition: climate.h:204
float target_temperature_low
Definition: climate.h:552
void set_visual_temperature_step_override(float visual_temperature_step_override)
Definition: climate.cpp:443
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:72
BedjetMode mode
BedJet operating mode.
Definition: bedjet_base.h:102
ClimatePreset
Enum for all preset modes.
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:260
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:451
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:512
optional< ClimateFanMode > fan_mode_
Definition: climate.h:116
const optional< float > & get_target_temperature_low() const
Definition: climate.cpp:262
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:553
bool uses_custom_fan_mode
Definition: climate.h:538
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:229
ClimateSwingMode swing_mode
Definition: climate.h:548
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:314
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:475
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition: climate.cpp:252
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:452
Device is in comfort preset.
Definition: climate_mode.h:90
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:248
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: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:210
uint8_t custom_preset
Definition: climate.h:546
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:193
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:153
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition: climate.cpp:423
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:74
void set_visual_max_temperature_override(float visual_max_temperature_override)
Definition: climate.cpp:440
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:437
The fan mode is set to Off.
Definition: climate_mode.h:50
const optional< float > & get_target_temperature() const
Definition: climate.cpp:261
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:384
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:526
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:540
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:256
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:269
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:129
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:532
bool uses_custom_preset
Definition: climate.h:543
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:329
Definition: a4988.cpp:4
optional< ClimateMode > mode_
Definition: climate.h:112
void dump_traits_(const char *tag)
Definition: climate.cpp:536
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:321
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:263
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:530
uint8_t custom_fan_mode
Definition: climate.h:541
optional< float > target_temperature_low_
Definition: climate.h:114
float target_temperature
Definition: climate.h:550
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
Definition: climate.cpp:454
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:522
ClimatePreset preset
Definition: climate.h:545
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:97
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.