ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
climate.cpp
Go to the documentation of this file.
1#include "climate.h"
5
6namespace esphome {
7namespace climate {
8
9static const char *const TAG = "climate";
10
11// Memory-efficient lookup tables
12struct StringToUint8 {
13 const char *str;
14 const uint8_t value;
15};
16
17constexpr StringToUint8 CLIMATE_MODES_BY_STR[] = {
18 {"OFF", CLIMATE_MODE_OFF},
19 {"AUTO", CLIMATE_MODE_AUTO},
20 {"COOL", CLIMATE_MODE_COOL},
21 {"HEAT", CLIMATE_MODE_HEAT},
22 {"FAN_ONLY", CLIMATE_MODE_FAN_ONLY},
23 {"DRY", CLIMATE_MODE_DRY},
24 {"HEAT_COOL", CLIMATE_MODE_HEAT_COOL},
25};
26
27constexpr StringToUint8 CLIMATE_FAN_MODES_BY_STR[] = {
28 {"ON", CLIMATE_FAN_ON}, {"OFF", CLIMATE_FAN_OFF}, {"AUTO", CLIMATE_FAN_AUTO},
29 {"LOW", CLIMATE_FAN_LOW}, {"MEDIUM", CLIMATE_FAN_MEDIUM}, {"HIGH", CLIMATE_FAN_HIGH},
30 {"MIDDLE", CLIMATE_FAN_MIDDLE}, {"FOCUS", CLIMATE_FAN_FOCUS}, {"DIFFUSE", CLIMATE_FAN_DIFFUSE},
31 {"QUIET", CLIMATE_FAN_QUIET},
32};
33
34constexpr StringToUint8 CLIMATE_PRESETS_BY_STR[] = {
35 {"ECO", CLIMATE_PRESET_ECO}, {"AWAY", CLIMATE_PRESET_AWAY}, {"BOOST", CLIMATE_PRESET_BOOST},
36 {"COMFORT", CLIMATE_PRESET_COMFORT}, {"HOME", CLIMATE_PRESET_HOME}, {"SLEEP", CLIMATE_PRESET_SLEEP},
37 {"ACTIVITY", CLIMATE_PRESET_ACTIVITY}, {"NONE", CLIMATE_PRESET_NONE},
38};
39
40constexpr StringToUint8 CLIMATE_SWING_MODES_BY_STR[] = {
41 {"OFF", CLIMATE_SWING_OFF},
42 {"BOTH", CLIMATE_SWING_BOTH},
43 {"VERTICAL", CLIMATE_SWING_VERTICAL},
44 {"HORIZONTAL", CLIMATE_SWING_HORIZONTAL},
45};
46
48 this->parent_->control_callback_.call(*this);
49 ESP_LOGD(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
50 this->validate_();
51 if (this->mode_.has_value()) {
52 const LogString *mode_s = climate_mode_to_string(*this->mode_);
53 ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(mode_s));
54 }
55 if (this->custom_fan_mode_ != nullptr) {
56 this->fan_mode_.reset();
57 ESP_LOGD(TAG, " Custom Fan: %s", this->custom_fan_mode_);
58 }
59 if (this->fan_mode_.has_value()) {
60 this->custom_fan_mode_ = nullptr;
61 const LogString *fan_mode_s = climate_fan_mode_to_string(*this->fan_mode_);
62 ESP_LOGD(TAG, " Fan: %s", LOG_STR_ARG(fan_mode_s));
63 }
64 if (this->custom_preset_ != nullptr) {
65 this->preset_.reset();
66 ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset_);
67 }
68 if (this->preset_.has_value()) {
69 this->custom_preset_ = nullptr;
70 const LogString *preset_s = climate_preset_to_string(*this->preset_);
71 ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(preset_s));
72 }
73 if (this->swing_mode_.has_value()) {
74 const LogString *swing_mode_s = climate_swing_mode_to_string(*this->swing_mode_);
75 ESP_LOGD(TAG, " Swing: %s", LOG_STR_ARG(swing_mode_s));
76 }
77 if (this->target_temperature_.has_value()) {
78 ESP_LOGD(TAG, " Target Temperature: %.2f", *this->target_temperature_);
79 }
81 ESP_LOGD(TAG, " Target Temperature Low: %.2f", *this->target_temperature_low_);
82 }
84 ESP_LOGD(TAG, " Target Temperature High: %.2f", *this->target_temperature_high_);
85 }
86 if (this->target_humidity_.has_value()) {
87 ESP_LOGD(TAG, " Target Humidity: %.0f", *this->target_humidity_);
88 }
89 this->parent_->control(*this);
90}
91
93 auto traits = this->parent_->get_traits();
94 if (this->mode_.has_value()) {
95 auto mode = *this->mode_;
96 if (!traits.supports_mode(mode)) {
97 ESP_LOGW(TAG, " Mode %s not supported", LOG_STR_ARG(climate_mode_to_string(mode)));
98 this->mode_.reset();
99 }
100 }
101 if (this->custom_fan_mode_ != nullptr) {
102 if (!traits.supports_custom_fan_mode(this->custom_fan_mode_)) {
103 ESP_LOGW(TAG, " Fan Mode %s not supported", this->custom_fan_mode_);
104 this->custom_fan_mode_ = nullptr;
105 }
106 } else if (this->fan_mode_.has_value()) {
107 auto fan_mode = *this->fan_mode_;
108 if (!traits.supports_fan_mode(fan_mode)) {
109 ESP_LOGW(TAG, " Fan Mode %s not supported", LOG_STR_ARG(climate_fan_mode_to_string(fan_mode)));
110 this->fan_mode_.reset();
111 }
112 }
113 if (this->custom_preset_ != nullptr) {
114 if (!traits.supports_custom_preset(this->custom_preset_)) {
115 ESP_LOGW(TAG, " Preset %s not supported", this->custom_preset_);
116 this->custom_preset_ = nullptr;
117 }
118 } else if (this->preset_.has_value()) {
119 auto preset = *this->preset_;
120 if (!traits.supports_preset(preset)) {
121 ESP_LOGW(TAG, " Preset %s not supported", LOG_STR_ARG(climate_preset_to_string(preset)));
122 this->preset_.reset();
123 }
124 }
125 if (this->swing_mode_.has_value()) {
126 auto swing_mode = *this->swing_mode_;
127 if (!traits.supports_swing_mode(swing_mode)) {
128 ESP_LOGW(TAG, " Swing Mode %s not supported", LOG_STR_ARG(climate_swing_mode_to_string(swing_mode)));
129 this->swing_mode_.reset();
130 }
131 }
132 if (this->target_temperature_.has_value()) {
133 auto target = *this->target_temperature_;
134 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
136 ESP_LOGW(TAG, " Cannot set target temperature for climate device "
137 "with two-point target temperature");
139 } else if (std::isnan(target)) {
140 ESP_LOGW(TAG, " Target temperature must not be NAN");
142 }
143 }
144 if (this->target_temperature_low_.has_value() || this->target_temperature_high_.has_value()) {
145 if (!traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
147 ESP_LOGW(TAG, " Cannot set low/high target temperature");
150 }
151 }
152 if (this->target_temperature_low_.has_value() && std::isnan(*this->target_temperature_low_)) {
153 ESP_LOGW(TAG, " Target temperature low must not be NAN");
155 }
156 if (this->target_temperature_high_.has_value() && std::isnan(*this->target_temperature_high_)) {
157 ESP_LOGW(TAG, " Target temperature high must not be NAN");
159 }
160 if (this->target_temperature_low_.has_value() && this->target_temperature_high_.has_value()) {
161 float low = *this->target_temperature_low_;
162 float high = *this->target_temperature_high_;
163 if (low > high) {
164 ESP_LOGW(TAG, " Target temperature low %.2f must be less than target temperature high %.2f", low, high);
167 }
168 }
169}
170
172 this->mode_ = mode;
173 return *this;
174}
175
177 for (const auto &mode_entry : CLIMATE_MODES_BY_STR) {
178 if (str_equals_case_insensitive(mode, mode_entry.str)) {
179 this->set_mode(static_cast<ClimateMode>(mode_entry.value));
180 return *this;
181 }
182 }
183 ESP_LOGW(TAG, "'%s' - Unrecognized mode %s", this->parent_->get_name().c_str(), mode.c_str());
184 return *this;
185}
186
188 this->fan_mode_ = fan_mode;
189 this->custom_fan_mode_ = nullptr;
190 return *this;
191}
192
194 // Check if it's a standard enum mode first
195 for (const auto &mode_entry : CLIMATE_FAN_MODES_BY_STR) {
196 if (str_equals_case_insensitive(custom_fan_mode, mode_entry.str)) {
197 return this->set_fan_mode(static_cast<ClimateFanMode>(mode_entry.value));
198 }
199 }
200 // Find the matching pointer from parent climate device
201 if (const char *mode_ptr = this->parent_->find_custom_fan_mode_(custom_fan_mode)) {
202 this->custom_fan_mode_ = mode_ptr;
203 this->fan_mode_.reset();
204 return *this;
205 }
206 ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %s", this->parent_->get_name().c_str(), custom_fan_mode);
207 return *this;
208}
209
210ClimateCall &ClimateCall::set_fan_mode(const std::string &fan_mode) { return this->set_fan_mode(fan_mode.c_str()); }
211
213 if (fan_mode.has_value()) {
214 this->set_fan_mode(fan_mode.value());
215 }
216 return *this;
217}
218
220 this->preset_ = preset;
221 this->custom_preset_ = nullptr;
222 return *this;
223}
224
226 // Check if it's a standard enum preset first
227 for (const auto &preset_entry : CLIMATE_PRESETS_BY_STR) {
228 if (str_equals_case_insensitive(custom_preset, preset_entry.str)) {
229 return this->set_preset(static_cast<ClimatePreset>(preset_entry.value));
230 }
231 }
232 // Find the matching pointer from parent climate device
233 if (const char *preset_ptr = this->parent_->find_custom_preset_(custom_preset)) {
234 this->custom_preset_ = preset_ptr;
235 this->preset_.reset();
236 return *this;
237 }
238 ESP_LOGW(TAG, "'%s' - Unrecognized preset %s", this->parent_->get_name().c_str(), custom_preset);
239 return *this;
240}
241
242ClimateCall &ClimateCall::set_preset(const std::string &preset) { return this->set_preset(preset.c_str()); }
243
245 if (preset.has_value()) {
246 this->set_preset(preset.value());
247 }
248 return *this;
249}
250
255
257 for (const auto &mode_entry : CLIMATE_SWING_MODES_BY_STR) {
258 if (str_equals_case_insensitive(swing_mode, mode_entry.str)) {
259 this->set_swing_mode(static_cast<ClimateSwingMode>(mode_entry.value));
260 return *this;
261 }
262 }
263 ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %s", this->parent_->get_name().c_str(), swing_mode.c_str());
264 return *this;
265}
266
271
276
281
286
291
292const optional<ClimateMode> &ClimateCall::get_mode() const { return this->mode_; }
296
301
306
311
316
321
323 this->fan_mode_ = fan_mode;
324 this->custom_fan_mode_ = nullptr;
325 return *this;
326}
327
329 this->preset_ = preset;
330 this->custom_preset_ = nullptr;
331 return *this;
332}
333
338
339void Climate::add_on_state_callback(std::function<void(Climate &)> &&callback) {
340 this->state_callback_.add(std::move(callback));
341}
342
343void Climate::add_on_control_callback(std::function<void(ClimateCall &)> &&callback) {
344 this->control_callback_.add(std::move(callback));
345}
346
347// Random 32bit value; If this changes existing restore preferences are invalidated
348static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;
349
352 RESTORE_STATE_VERSION);
353 ClimateDeviceRestoreState recovered{};
354 if (!this->rtc_.load(&recovered))
355 return {};
356 return recovered;
357}
358
360#if (defined(USE_ESP_IDF) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \
361 !defined(CLANG_TIDY)
362#pragma GCC diagnostic ignored "-Wclass-memaccess"
363#define TEMP_IGNORE_MEMACCESS
364#endif
366 // initialize as zero to prevent random data on stack triggering erase
367 memset(&state, 0, sizeof(ClimateDeviceRestoreState));
368#ifdef TEMP_IGNORE_MEMACCESS
369#pragma GCC diagnostic pop
370#undef TEMP_IGNORE_MEMACCESS
371#endif
372
373 state.mode = this->mode;
374 auto traits = this->get_traits();
377 state.target_temperature_low = this->target_temperature_low;
378 state.target_temperature_high = this->target_temperature_high;
379 } else {
380 state.target_temperature = this->target_temperature;
381 }
383 state.target_humidity = this->target_humidity;
384 }
386 state.uses_custom_fan_mode = false;
387 state.fan_mode = this->fan_mode.value();
388 }
389 if (!traits.get_supported_custom_fan_modes().empty() && this->has_custom_fan_mode()) {
390 state.uses_custom_fan_mode = true;
391 const auto &supported = traits.get_supported_custom_fan_modes();
392 // std::vector maintains insertion order
393 size_t i = 0;
394 for (const char *mode : supported) {
395 if (strcmp(mode, this->custom_fan_mode_) == 0) {
396 state.custom_fan_mode = i;
397 break;
398 }
399 i++;
400 }
401 }
403 state.uses_custom_preset = false;
404 state.preset = this->preset.value();
405 }
406 if (!traits.get_supported_custom_presets().empty() && this->has_custom_preset()) {
407 state.uses_custom_preset = true;
408 const auto &supported = traits.get_supported_custom_presets();
409 // std::vector maintains insertion order
410 size_t i = 0;
411 for (const char *preset : supported) {
412 if (strcmp(preset, this->custom_preset_) == 0) {
413 state.custom_preset = i;
414 break;
415 }
416 i++;
417 }
418 }
420 state.swing_mode = this->swing_mode;
421 }
422
423 this->rtc_.save(&state);
424}
425
427 ESP_LOGD(TAG, "'%s' - Sending state:", this->name_.c_str());
428 auto traits = this->get_traits();
429
430 ESP_LOGD(TAG, " Mode: %s", LOG_STR_ARG(climate_mode_to_string(this->mode)));
432 ESP_LOGD(TAG, " Action: %s", LOG_STR_ARG(climate_action_to_string(this->action)));
433 }
434 if (traits.get_supports_fan_modes() && this->fan_mode.has_value()) {
435 ESP_LOGD(TAG, " Fan Mode: %s", LOG_STR_ARG(climate_fan_mode_to_string(this->fan_mode.value())));
436 }
437 if (!traits.get_supported_custom_fan_modes().empty() && this->has_custom_fan_mode()) {
438 ESP_LOGD(TAG, " Custom Fan Mode: %s", this->custom_fan_mode_);
439 }
440 if (traits.get_supports_presets() && this->preset.has_value()) {
441 ESP_LOGD(TAG, " Preset: %s", LOG_STR_ARG(climate_preset_to_string(this->preset.value())));
442 }
443 if (!traits.get_supported_custom_presets().empty() && this->has_custom_preset()) {
444 ESP_LOGD(TAG, " Custom Preset: %s", this->custom_preset_);
445 }
447 ESP_LOGD(TAG, " Swing Mode: %s", LOG_STR_ARG(climate_swing_mode_to_string(this->swing_mode)));
448 }
450 ESP_LOGD(TAG, " Current Temperature: %.2f°C", this->current_temperature);
451 }
454 ESP_LOGD(TAG, " Target Temperature: Low: %.2f°C High: %.2f°C", this->target_temperature_low,
456 } else {
457 ESP_LOGD(TAG, " Target Temperature: %.2f°C", this->target_temperature);
458 }
460 ESP_LOGD(TAG, " Current Humidity: %.0f%%", this->current_humidity);
461 }
463 ESP_LOGD(TAG, " Target Humidity: %.0f%%", this->target_humidity);
464 }
465
466 // Send state to frontend
467 this->state_callback_.call(*this);
468#if defined(USE_CLIMATE) && defined(USE_CONTROLLER_REGISTRY)
470#endif
471 // Save state
472 this->save_state_();
473}
474
496
497void Climate::set_visual_min_temperature_override(float visual_min_temperature_override) {
498 this->visual_min_temperature_override_ = visual_min_temperature_override;
499}
500
501void Climate::set_visual_max_temperature_override(float visual_max_temperature_override) {
502 this->visual_max_temperature_override_ = visual_max_temperature_override;
503}
504
509
510void Climate::set_visual_min_humidity_override(float visual_min_humidity_override) {
511 this->visual_min_humidity_override_ = visual_min_humidity_override;
512}
513
514void Climate::set_visual_max_humidity_override(float visual_max_humidity_override) {
515 this->visual_max_humidity_override_ = visual_max_humidity_override;
516}
517
519
521 auto call = climate->make_call();
522 auto traits = climate->get_traits();
523 call.set_mode(this->mode);
524 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
526 call.set_target_temperature_low(this->target_temperature_low);
527 call.set_target_temperature_high(this->target_temperature_high);
528 } else {
529 call.set_target_temperature(this->target_temperature);
530 }
531 if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) {
532 call.set_target_humidity(this->target_humidity);
533 }
534 if (this->uses_custom_fan_mode) {
535 if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
536 call.fan_mode_.reset();
537 call.custom_fan_mode_ = traits.get_supported_custom_fan_modes()[this->custom_fan_mode];
538 }
539 } else if (traits.supports_fan_mode(this->fan_mode)) {
540 call.set_fan_mode(this->fan_mode);
541 }
542 if (this->uses_custom_preset) {
543 if (this->custom_preset < traits.get_supported_custom_presets().size()) {
544 call.preset_.reset();
545 call.custom_preset_ = traits.get_supported_custom_presets()[this->custom_preset];
546 }
547 } else if (traits.supports_preset(this->preset)) {
548 call.set_preset(this->preset);
549 }
550 if (traits.supports_swing_mode(this->swing_mode)) {
551 call.set_swing_mode(this->swing_mode);
552 }
553 return call;
554}
555
557 auto traits = climate->get_traits();
558 climate->mode = this->mode;
559 if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE |
563 } else {
564 climate->target_temperature = this->target_temperature;
565 }
566 if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) {
567 climate->target_humidity = this->target_humidity;
568 }
569 if (this->uses_custom_fan_mode) {
570 if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
571 climate->fan_mode.reset();
572 climate->custom_fan_mode_ = traits.get_supported_custom_fan_modes()[this->custom_fan_mode];
573 }
574 } else if (traits.supports_fan_mode(this->fan_mode)) {
575 climate->fan_mode = this->fan_mode;
576 climate->clear_custom_fan_mode_();
577 }
578 if (this->uses_custom_preset) {
579 if (this->custom_preset < traits.get_supported_custom_presets().size()) {
580 climate->preset.reset();
581 climate->custom_preset_ = traits.get_supported_custom_presets()[this->custom_preset];
582 }
583 } else if (traits.supports_preset(this->preset)) {
584 climate->preset = this->preset;
585 climate->clear_custom_preset_();
586 }
587 if (traits.supports_swing_mode(this->swing_mode)) {
588 climate->swing_mode = this->swing_mode;
589 }
590 climate->publish_state();
591}
592
612template<typename T> bool set_primary_mode(optional<T> &primary, const char *&custom_ptr, T value) {
613 // Clear the custom mode (mutual exclusion)
614 bool changed = custom_ptr != nullptr;
615 custom_ptr = nullptr;
616 // Set the primary mode
617 if (changed || !primary.has_value() || primary.value() != value) {
618 primary = value;
619 return true;
620 }
621 return false;
622}
623
645template<typename T>
646bool set_custom_mode(const char *&custom_ptr, optional<T> &primary, const char *found_ptr, bool has_custom) {
647 if (found_ptr != nullptr) {
648 // Clear the primary mode (mutual exclusion)
649 bool changed = primary.has_value();
650 primary.reset();
651 // Set the custom mode (pointer is validated by caller from traits)
652 if (changed || custom_ptr != found_ptr) {
653 custom_ptr = found_ptr;
654 return true;
655 }
656 return false;
657 }
658 // Mode not found in supported modes, clear it if currently set
659 if (has_custom) {
660 custom_ptr = nullptr;
661 return true;
662 }
663 return false;
664}
665
667 return set_primary_mode(this->fan_mode, this->custom_fan_mode_, mode);
668}
669
671 auto traits = this->get_traits();
672 return set_custom_mode<ClimateFanMode>(this->custom_fan_mode_, this->fan_mode, traits.find_custom_fan_mode_(mode),
673 this->has_custom_fan_mode());
674}
675
676void Climate::clear_custom_fan_mode_() { this->custom_fan_mode_ = nullptr; }
677
678bool Climate::set_preset_(ClimatePreset preset) { return set_primary_mode(this->preset, this->custom_preset_, preset); }
679
681 auto traits = this->get_traits();
682 return set_custom_mode<ClimatePreset>(this->custom_preset_, this->preset, traits.find_custom_preset_(preset),
683 this->has_custom_preset());
684}
685
686void Climate::clear_custom_preset_() { this->custom_preset_ = nullptr; }
687
689 return this->get_traits().find_custom_fan_mode_(custom_fan_mode);
690}
691
693 return this->get_traits().find_custom_preset_(custom_preset);
694}
695
696void Climate::dump_traits_(const char *tag) {
697 auto traits = this->get_traits();
698 ESP_LOGCONFIG(tag, "ClimateTraits:");
699 ESP_LOGCONFIG(tag,
700 " Visual settings:\n"
701 " - Min temperature: %.1f\n"
702 " - Max temperature: %.1f\n"
703 " - Temperature step:\n"
704 " Target: %.1f",
708 ESP_LOGCONFIG(tag, " Current: %.1f", traits.get_visual_current_temperature_step());
709 }
712 ESP_LOGCONFIG(tag,
713 " - Min humidity: %.0f\n"
714 " - Max humidity: %.0f",
716 }
719 ESP_LOGCONFIG(tag, " Supports two-point target temperature");
720 }
722 ESP_LOGCONFIG(tag, " Supports current temperature");
723 }
725 ESP_LOGCONFIG(tag, " Supports target humidity");
726 }
728 ESP_LOGCONFIG(tag, " Supports current humidity");
729 }
731 ESP_LOGCONFIG(tag, " Supports action");
732 }
734 ESP_LOGCONFIG(tag, " Supported modes:");
736 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_mode_to_string(m)));
737 }
739 ESP_LOGCONFIG(tag, " Supported fan modes:");
741 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_fan_mode_to_string(m)));
742 }
743 if (!traits.get_supported_custom_fan_modes().empty()) {
744 ESP_LOGCONFIG(tag, " Supported custom fan modes:");
745 for (const char *s : traits.get_supported_custom_fan_modes())
746 ESP_LOGCONFIG(tag, " - %s", s);
747 }
749 ESP_LOGCONFIG(tag, " Supported presets:");
751 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_preset_to_string(p)));
752 }
753 if (!traits.get_supported_custom_presets().empty()) {
754 ESP_LOGCONFIG(tag, " Supported custom presets:");
755 for (const char *s : traits.get_supported_custom_presets())
756 ESP_LOGCONFIG(tag, " - %s", s);
757 }
759 ESP_LOGCONFIG(tag, " Supported swing modes:");
761 ESP_LOGCONFIG(tag, " - %s", LOG_STR_ARG(climate_swing_mode_to_string(m)));
762 }
763}
764
765} // namespace climate
766} // namespace esphome
BedjetMode mode
BedJet operating mode.
uint8_t m
Definition bl0906.h:1
static void notify_climate_update(climate::Climate *obj)
bool save(const T *src)
Definition preferences.h:21
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
const StringRef & get_name() const
uint32_t get_preference_hash()
Get a unique hash for storing preferences/settings for this entity.
constexpr bool empty() const
Check if the set is empty.
constexpr const char * c_str() const
Definition string_ref.h:69
This class is used to encode all control actions on a climate device.
Definition climate.h:33
const optional< ClimateSwingMode > & get_swing_mode() const
Definition climate.cpp:294
optional< float > target_temperature_high_
Definition climate.h:121
const optional< float > & get_target_humidity() const
Definition climate.cpp:290
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
Definition climate.cpp:267
const optional< float > & get_target_temperature_low() const
Definition climate.cpp:288
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
Definition climate.cpp:251
optional< ClimateFanMode > fan_mode_
Definition climate.h:124
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
Definition climate.cpp:272
optional< float > target_temperature_
Definition climate.h:119
const optional< float > & get_target_temperature() const
Definition climate.cpp:287
const optional< ClimatePreset > & get_preset() const
Definition climate.cpp:295
optional< ClimateSwingMode > swing_mode_
Definition climate.h:125
optional< ClimateMode > mode_
Definition climate.h:123
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
Definition climate.cpp:219
const optional< float > & get_target_temperature_high() const
Definition climate.cpp:289
const optional< ClimateFanMode > & get_fan_mode() const
Definition climate.cpp:293
optional< float > target_humidity_
Definition climate.h:122
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
Definition climate.cpp:187
optional< ClimatePreset > preset_
Definition climate.h:126
ClimateCall & set_target_humidity(float target_humidity)
Set the target humidity of the climate device.
Definition climate.cpp:282
optional< float > target_temperature_low_
Definition climate.h:120
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
Definition climate.cpp:277
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
Definition climate.cpp:171
const optional< ClimateMode > & get_mode() const
Definition climate.cpp:292
ClimateDevice - This is the base class for all climate integrations.
Definition climate.h:178
ClimateMode mode
The active mode of the climate device.
Definition climate.h:256
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
Definition climate.h:250
optional< float > visual_max_humidity_override_
Definition climate.h:330
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition climate.cpp:475
float target_temperature
The target temperature of the climate device.
Definition climate.h:237
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition climate.h:233
void set_visual_min_humidity_override(float visual_min_humidity_override)
Definition climate.cpp:510
optional< float > visual_current_temperature_step_override_
Definition climate.h:328
void dump_traits_(const char *tag)
Definition climate.cpp:696
CallbackManager< void(ClimateCall &)> control_callback_
Definition climate.h:323
CallbackManager< void(Climate &)> state_callback_
Definition climate.h:322
ClimateSwingMode swing_mode
The active swing mode of the climate device.
Definition climate.h:262
optional< float > visual_target_temperature_step_override_
Definition climate.h:327
void save_state_()
Internal method to save the state of the climate device to recover memory.
Definition climate.cpp:359
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:240
void set_visual_max_humidity_override(float visual_max_humidity_override)
Definition climate.cpp:514
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:339
virtual ClimateTraits traits()=0
Get the default traits of this climate device.
bool set_preset_(ClimatePreset preset)
Set preset. Reset custom preset. Return true if preset has been changed.
Definition climate.cpp:678
bool set_custom_preset_(const char *preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
Definition climate.cpp:680
const char * find_custom_fan_mode_(const char *custom_fan_mode)
Find and return the matching custom fan mode pointer from traits, or nullptr if not found.
Definition climate.cpp:688
void set_visual_max_temperature_override(float visual_max_temperature_override)
Definition climate.cpp:501
optional< float > visual_min_humidity_override_
Definition climate.h:329
void clear_custom_preset_()
Clear custom preset.
Definition climate.cpp:686
optional< float > visual_max_temperature_override_
Definition climate.h:326
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
Definition climate.cpp:666
optional< float > visual_min_temperature_override_
Definition climate.h:325
const char * find_custom_preset_(const char *custom_preset)
Find and return the matching custom preset pointer from traits, or nullptr if not found.
Definition climate.cpp:692
void clear_custom_fan_mode_()
Clear custom fan mode.
Definition climate.cpp:676
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:343
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition climate.h:230
ClimateAction action
The active state of the climate device.
Definition climate.h:259
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Definition climate.cpp:518
virtual void control(const ClimateCall &call)=0
Control the climate device, this is a virtual method that each climate integration must implement.
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition climate.cpp:426
void set_visual_temperature_step_override(float target, float current)
Definition climate.cpp:505
ESPPreferenceObject rtc_
Definition climate.h:324
optional< ClimatePreset > preset
The active preset of the climate device.
Definition climate.h:253
void set_visual_min_temperature_override(float visual_min_temperature_override)
Definition climate.cpp:497
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
Definition climate.cpp:350
float target_humidity
The target humidity of the climate device.
Definition climate.h:247
bool set_custom_fan_mode_(const char *mode)
Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed.
Definition climate.cpp:670
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
Definition climate.h:242
void set_visual_max_temperature(float visual_max_temperature)
const ClimatePresetMask & get_supported_presets() const
const std::vector< const char * > & get_supported_custom_fan_modes() const
const ClimateSwingModeMask & get_supported_swing_modes() const
void set_visual_target_temperature_step(float temperature_step)
float get_visual_current_temperature_step() const
void set_visual_min_temperature(float visual_min_temperature)
const ClimateFanModeMask & get_supported_fan_modes() const
float get_visual_target_temperature_step() const
void set_visual_min_humidity(float visual_min_humidity)
void set_visual_current_temperature_step(float temperature_step)
bool has_feature_flags(uint32_t feature_flags) const
void set_visual_max_humidity(float visual_max_humidity)
const char * find_custom_fan_mode_(const char *custom_fan_mode) const
Find and return the matching custom fan mode pointer from supported modes, or nullptr if not found Th...
const char * find_custom_preset_(const char *custom_preset) const
Find and return the matching custom preset pointer from supported presets, or nullptr if not found Th...
const std::vector< const char * > & get_supported_custom_presets() const
const ClimateModeMask & get_supported_modes() const
bool has_value() const
Definition optional.h:92
value_type const & value() const
Definition optional.h:94
float target_temperature_high
Definition climate.h:3
float target_humidity
Definition climate.h:19
ClimateSwingMode swing_mode
Definition climate.h:11
float target_temperature
Definition climate.h:0
uint8_t custom_preset
Definition climate.h:9
ClimateFanMode fan_mode
Definition climate.h:3
ClimatePreset preset
Definition climate.h:8
float target_temperature_low
Definition climate.h:2
uint8_t custom_fan_mode
Definition climate.h:4
bool state
Definition fan.h:0
const LogString * climate_action_to_string(ClimateAction action)
Convert the given ClimateAction to a human-readable string.
constexpr StringToUint8 CLIMATE_MODES_BY_STR[]
Definition climate.cpp:17
@ CLIMATE_SUPPORTS_CURRENT_HUMIDITY
@ CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
@ CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE
const LogString * climate_swing_mode_to_string(ClimateSwingMode swing_mode)
Convert the given ClimateSwingMode to a human-readable string.
constexpr StringToUint8 CLIMATE_PRESETS_BY_STR[]
Definition climate.cpp:34
const LogString * climate_preset_to_string(ClimatePreset preset)
Convert the given PresetMode to a human-readable string.
ClimatePreset
Enum for all preset modes NOTE: If adding values, update ClimatePresetMask in climate_traits....
@ CLIMATE_PRESET_NONE
No preset is active.
@ CLIMATE_PRESET_COMFORT
Device is in comfort preset.
@ CLIMATE_PRESET_AWAY
Device is in away preset.
@ CLIMATE_PRESET_BOOST
Device is in boost preset.
@ CLIMATE_PRESET_ACTIVITY
Device is reacting to activity (e.g., movement sensors)
@ CLIMATE_PRESET_SLEEP
Device is prepared for sleep.
@ CLIMATE_PRESET_HOME
Device is in home preset.
@ CLIMATE_PRESET_ECO
Device is running an energy-saving preset.
const LogString * climate_fan_mode_to_string(ClimateFanMode fan_mode)
Convert the given ClimateFanMode to a human-readable string.
constexpr StringToUint8 CLIMATE_FAN_MODES_BY_STR[]
Definition climate.cpp:27
ClimateSwingMode
Enum for all modes a climate swing can be in NOTE: If adding values, update ClimateSwingModeMask in c...
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
ClimateMode
Enum for all modes a climate device can be in.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
@ CLIMATE_MODE_AUTO
The climate device is adjusting the temperature dynamically.
const LogString * climate_mode_to_string(ClimateMode mode)
Convert the given ClimateMode to a human-readable string.
bool set_primary_mode(optional< T > &primary, const char *&custom_ptr, T value)
Template helper for setting primary modes (fan_mode, preset) with mutual exclusion.
Definition climate.cpp:612
constexpr StringToUint8 CLIMATE_SWING_MODES_BY_STR[]
Definition climate.cpp:40
bool set_custom_mode(const char *&custom_ptr, optional< T > &primary, const char *found_ptr, bool has_custom)
Template helper for setting custom modes (custom_fan_mode_, custom_preset_) with mutual exclusion.
Definition climate.cpp:646
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_DIFFUSE
The fan mode is set to Diffuse.
@ CLIMATE_FAN_ON
The fan mode is set to On.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_FOCUS
The fan mode is set to Focus.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_MIDDLE
The fan mode is set to Middle.
@ CLIMATE_FAN_QUIET
The fan mode is set to Quiet.
@ CLIMATE_FAN_OFF
The fan mode is set to Off.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
ESPPreferences * global_preferences
bool str_equals_case_insensitive(const std::string &a, const std::string &b)
Compare strings for equality in case-insensitive manner.
Definition helpers.cpp:161
Struct used to save the state of the climate device in restore memory.
Definition climate.h:135
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
Definition climate.cpp:520
void apply(Climate *climate)
Apply these settings to the climate device.
Definition climate.cpp:556