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