7 static const char *
const TAG =
"climate";
15 ESP_LOGD(TAG,
" Mode: %s", LOG_STR_ARG(mode_s));
24 ESP_LOGD(TAG,
" Fan: %s", LOG_STR_ARG(fan_mode_s));
33 ESP_LOGD(TAG,
" Preset: %s", LOG_STR_ARG(preset_s));
37 ESP_LOGD(TAG,
" Swing: %s", LOG_STR_ARG(swing_mode_s));
54 if (!traits.supports_mode(
mode)) {
62 ESP_LOGW(TAG,
" Fan Mode %s is not supported by this device!",
custom_fan_mode.c_str());
67 if (!traits.supports_fan_mode(
fan_mode)) {
68 ESP_LOGW(TAG,
" Fan Mode %s is not supported by this device!",
76 ESP_LOGW(TAG,
" Preset %s is not supported by this device!",
custom_preset.c_str());
81 if (!traits.supports_preset(
preset)) {
89 ESP_LOGW(TAG,
" Swing Mode %s is not supported by this device!",
96 if (traits.get_supports_two_point_target_temperature()) {
97 ESP_LOGW(TAG,
" Cannot set target temperature for climate device " 98 "with two-point target temperature!");
100 }
else if (std::isnan(target)) {
101 ESP_LOGW(TAG,
" Target temperature must not be NAN!");
106 if (!traits.get_supports_two_point_target_temperature()) {
107 ESP_LOGW(TAG,
" Cannot set low/high target temperature for this device!");
113 ESP_LOGW(TAG,
" Target temperature low must not be NAN!");
117 ESP_LOGW(TAG,
" Target temperature low must not be NAN!");
124 ESP_LOGW(TAG,
" Target temperature low %.2f must be smaller than target temperature high %.2f!", low, high);
185 ESP_LOGW(TAG,
"'%s' - Unrecognized fan mode %s", this->
parent_->
get_name().
c_str(), fan_mode.c_str());
223 ESP_LOGW(TAG,
"'%s' - Unrecognized preset %s", this->
parent_->
get_name().
c_str(), preset.c_str());
248 ESP_LOGW(TAG,
"'%s' - Unrecognized swing mode %s", this->
parent_->
get_name().
c_str(), swing_mode.c_str());
306 this->state_callback_.add(std::move(callback));
310 this->control_callback_.add(std::move(callback));
314 static const uint32_t RESTORE_STATE_VERSION = 0x848EA6ADUL;
318 RESTORE_STATE_VERSION);
320 if (!this->rtc_.load(&recovered))
325 #if (defined(USE_ESP_IDF) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(3, 0, 0))) && \ 327 #pragma GCC diagnostic ignored "-Wclass-memaccess" 328 #define TEMP_IGNORE_MEMACCESS 333 #ifdef TEMP_IGNORE_MEMACCESS 334 #pragma GCC diagnostic pop 335 #undef TEMP_IGNORE_MEMACCESS 339 auto traits = this->get_traits();
340 if (traits.get_supports_two_point_target_temperature()) {
346 if (traits.get_supports_fan_modes() &&
fan_mode.has_value()) {
347 state.uses_custom_fan_mode =
false;
350 if (!traits.get_supported_custom_fan_modes().empty() &&
custom_fan_mode.has_value()) {
351 state.uses_custom_fan_mode =
true;
352 const auto &supported = traits.get_supported_custom_fan_modes();
353 std::vector<std::string> vec{supported.begin(), supported.end()};
355 if (it != vec.end()) {
356 state.custom_fan_mode = std::distance(vec.begin(), it);
359 if (traits.get_supports_presets() &&
preset.has_value()) {
360 state.uses_custom_preset =
false;
363 if (!traits.get_supported_custom_presets().empty() &&
custom_preset.has_value()) {
364 state.uses_custom_preset =
true;
365 const auto &supported = traits.get_supported_custom_presets();
366 std::vector<std::string> vec{supported.begin(), supported.end()};
369 if (it != vec.cend()) {
370 state.custom_preset = std::distance(vec.begin(), it);
373 if (traits.get_supports_swing_modes()) {
377 this->rtc_.save(&
state);
380 ESP_LOGD(TAG,
"'%s' - Sending state:", this->name_.c_str());
381 auto traits = this->get_traits();
384 if (traits.get_supports_action()) {
387 if (traits.get_supports_fan_modes() && this->
fan_mode.has_value()) {
390 if (!traits.get_supported_custom_fan_modes().empty() && this->
custom_fan_mode.has_value()) {
391 ESP_LOGD(TAG,
" Custom Fan Mode: %s", this->
custom_fan_mode.value().c_str());
393 if (traits.get_supports_presets() && this->
preset.has_value()) {
396 if (!traits.get_supported_custom_presets().empty() && this->
custom_preset.has_value()) {
397 ESP_LOGD(TAG,
" Custom Preset: %s", this->
custom_preset.value().c_str());
399 if (traits.get_supports_swing_modes()) {
402 if (traits.get_supports_current_temperature()) {
403 ESP_LOGD(TAG,
" Current Temperature: %.2f°C", this->current_temperature);
405 if (traits.get_supports_two_point_target_temperature()) {
413 this->state_callback_.call(*
this);
419 auto traits = this->traits();
420 if (this->visual_min_temperature_override_.has_value()) {
421 traits.set_visual_min_temperature(*this->visual_min_temperature_override_);
423 if (this->visual_max_temperature_override_.has_value()) {
424 traits.set_visual_max_temperature(*this->visual_max_temperature_override_);
426 if (this->visual_target_temperature_step_override_.has_value()) {
427 traits.set_visual_target_temperature_step(*this->visual_target_temperature_step_override_);
428 traits.set_visual_current_temperature_step(*this->visual_current_temperature_step_override_);
435 this->visual_min_temperature_override_ = visual_min_temperature_override;
438 this->visual_max_temperature_override_ = visual_max_temperature_override;
441 this->visual_target_temperature_step_override_ = target;
442 this->visual_current_temperature_step_override_ = current;
450 call.set_mode(this->
mode);
451 if (traits.get_supports_two_point_target_temperature()) {
457 if (traits.get_supports_fan_modes() || !traits.get_supported_custom_fan_modes().empty()) {
460 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
461 call.set_preset(this->
preset);
463 if (traits.get_supports_swing_modes()) {
471 if (traits.get_supports_two_point_target_temperature()) {
482 const auto &modes = traits.get_supported_custom_fan_modes();
483 std::vector<std::string> modes_vec{modes.begin(), modes.end()};
493 const auto &presets = traits.get_supported_custom_presets();
494 std::vector<std::string> presets_vec{presets.begin(), presets.end()};
499 if (traits.get_supports_swing_modes()) {
508 if (is_changed || dst != src) {
530 auto traits = this->get_traits();
531 ESP_LOGCONFIG(tag,
"ClimateTraits:");
532 ESP_LOGCONFIG(tag,
" [x] Visual settings:");
533 ESP_LOGCONFIG(tag,
" - Min: %.1f", traits.get_visual_min_temperature());
534 ESP_LOGCONFIG(tag,
" - Max: %.1f", traits.get_visual_max_temperature());
535 ESP_LOGCONFIG(tag,
" - Step:");
536 ESP_LOGCONFIG(tag,
" Target: %.1f", traits.get_visual_target_temperature_step());
537 ESP_LOGCONFIG(tag,
" Current: %.1f", traits.get_visual_current_temperature_step());
538 if (traits.get_supports_current_temperature()) {
539 ESP_LOGCONFIG(tag,
" [x] Supports current temperature");
541 if (traits.get_supports_two_point_target_temperature()) {
542 ESP_LOGCONFIG(tag,
" [x] Supports two-point target temperature");
544 if (traits.get_supports_action()) {
545 ESP_LOGCONFIG(tag,
" [x] Supports action");
547 if (!traits.get_supported_modes().empty()) {
548 ESP_LOGCONFIG(tag,
" [x] Supported modes:");
552 if (!traits.get_supported_fan_modes().empty()) {
553 ESP_LOGCONFIG(tag,
" [x] Supported fan modes:");
557 if (!traits.get_supported_custom_fan_modes().empty()) {
558 ESP_LOGCONFIG(tag,
" [x] Supported custom fan modes:");
559 for (
const std::string &s : traits.get_supported_custom_fan_modes())
560 ESP_LOGCONFIG(tag,
" - %s", s.c_str());
562 if (!traits.get_supported_presets().empty()) {
563 ESP_LOGCONFIG(tag,
" [x] Supported presets:");
567 if (!traits.get_supported_custom_presets().empty()) {
568 ESP_LOGCONFIG(tag,
" [x] Supported custom presets:");
569 for (
const std::string &s : traits.get_supported_custom_presets())
570 ESP_LOGCONFIG(tag,
" - %s", s.c_str());
572 if (!traits.get_supported_swing_modes().empty()) {
573 ESP_LOGCONFIG(tag,
" [x] Supported swing modes:");
This class is used to encode all control actions on a climate device.
The fan mode is set to Low.
value_type const & value() const
The fan mode is set to Quiet.
ClimateSwingMode swing_mode
The active swing mode of the climate device.
float target_temperature_low
optional< std::string > custom_preset_
The fan mode is set to Both.
ClimatePreset
Enum for all preset modes.
float target_temperature
The target temperature of the climate device.
Device is in home preset.
const optional< ClimateMode > & get_mode() const
optional< float > target_temperature_
The fan mode is set to Middle.
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.
The climate device is set to heat to reach the target temperature.
CallbackManager< void(ClimateCall &)> control_callback_
Struct used to save the state of the climate device in restore memory.
ClimateMode mode
The active mode of the climate device.
bool set_alternative(optional< T1 > &dst, optional< T2 > &alt, const T1 &src)
optional< ClimateFanMode > fan_mode_
const optional< float > & get_target_temperature_low() const
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...
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
The fan mode is set to Diffuse.
optional< float > target_temperature_high_
The climate device is set to dry/humidity mode.
float target_temperature_high
bool uses_custom_fan_mode
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
ClimateSwingMode swing_mode
ClimateSwingMode
Enum for all modes a climate swing can be in.
bool supports_custom_preset(const std::string &custom_preset) const
Device is prepared for sleep.
optional< std::string > custom_fan_mode
The active custom fan mode of the climate device.
Device is in away preset.
bool supports_custom_fan_mode(const std::string &custom_fan_mode) const
void apply(Climate *climate)
Apply these settings to the climate device.
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
Device is in comfort preset.
const optional< std::string > & get_custom_preset() const
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
The fan mode is set to Horizontal.
The climate device is set to cool to reach the target temperature.
optional< ClimateSwingMode > swing_mode_
Device is reacting to activity (e.g., movement sensors)
const optional< ClimatePreset > & get_preset() const
The fan mode is set to Auto.
optional< ClimatePreset > preset
The active preset of the climate device.
ESPPreferences * global_preferences
optional< ClimatePreset > preset_
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
BedjetMode mode
BedJet operating mode.
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.
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
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.
The climate device is set to heat/cool to reach the target temperature.
The fan mode is set to Vertical.
void set_visual_max_temperature_override(float visual_max_temperature_override)
The fan mode is set to Focus.
const optional< std::string > & get_custom_fan_mode() const
void set_visual_min_temperature_override(float visual_min_temperature_override)
The fan mode is set to Off.
const optional< float > & get_target_temperature() const
optional< std::string > custom_fan_mode_
void publish_state()
Publish the state of the climate device, to be called from integrations.
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.
The fan mode is set to High.
ClimateMode
Enum for all modes a climate device can be in.
The swing mode is set to Off.
The climate device is off.
constexpr const char * c_str() const
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...
optional< std::string > custom_preset
The active custom preset mode of the climate device.
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
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.
void set_visual_temperature_step_override(float target, float current)
const optional< ClimateFanMode > & get_fan_mode() const
Device is in boost preset.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
The fan mode is set to On.
bool set_custom_preset_(const std::string &preset)
Set custom preset. Reset primary preset. Return true if preset has been changed.
const optional< ClimateSwingMode > & get_swing_mode() const
void save_state_()
Internal method to save the state of the climate device to recover memory.
Implementation of SPI Controller mode.
optional< ClimateMode > mode_
ClimateCall(Climate *parent)
void dump_traits_(const char *tag)
Device is running an energy-saving preset.
optional< ClimateDeviceRestoreState > restore_state_()
Restore the state of the climate device, call this from your setup() method.
The fan mode is set to Medium.
const optional< float > & get_target_temperature_high() const
The climate device only has the fan enabled, no heating or cooling is taking place.
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.
optional< float > target_temperature_low_
ClimateCall to_call(Climate *climate)
Convert this struct to a climate call that can be performed.
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
const StringRef & get_name() const
bool set_fan_mode_(ClimateFanMode mode)
Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
ClimateDevice - This is the base class for all climate integrations.
bool str_equals_case_insensitive(const std::string &a, const std::string &b)
Compare strings for equality in case-insensitive manner.
const LogString * climate_swing_mode_to_string(ClimateSwingMode swing_mode)
Convert the given ClimateSwingMode to a human-readable string.