From b4045b09632b4fe5f9d124f879597437d5f5f840 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 30 Oct 2025 20:04:55 -0500 Subject: [PATCH] simplify --- esphome/components/climate/climate.cpp | 4 ++-- esphome/components/demo/demo_climate.h | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/esphome/components/climate/climate.cpp b/esphome/components/climate/climate.cpp index 5bf32e4c28f..c95fcd90b76 100644 --- a/esphome/components/climate/climate.cpp +++ b/esphome/components/climate/climate.cpp @@ -628,7 +628,7 @@ bool Climate::set_custom_fan_mode_(const char *mode) { } // Mode not found in supported custom modes, clear it if currently set if (this->has_custom_fan_mode()) { - this->custom_fan_mode_ = nullptr; + this->clear_custom_fan_mode_(); return true; } return false; @@ -648,7 +648,7 @@ bool Climate::set_custom_preset_(const char *preset) { } // Preset not found in supported custom presets, clear it if currently set if (this->has_custom_preset()) { - this->custom_preset_ = nullptr; + this->clear_custom_preset_(); return true; } return false; diff --git a/esphome/components/demo/demo_climate.h b/esphome/components/demo/demo_climate.h index 84b16e7ec58..0a71ec6dab5 100644 --- a/esphome/components/demo/demo_climate.h +++ b/esphome/components/demo/demo_climate.h @@ -28,14 +28,14 @@ class DemoClimate : public climate::Climate, public Component { this->mode = climate::CLIMATE_MODE_AUTO; this->action = climate::CLIMATE_ACTION_COOLING; this->fan_mode = climate::CLIMATE_FAN_HIGH; - this->custom_preset = {"My Preset"}; + this->set_custom_preset_("My Preset"); break; case DemoClimateType::TYPE_3: this->current_temperature = 21.5; this->target_temperature_low = 21.0; this->target_temperature_high = 22.5; this->mode = climate::CLIMATE_MODE_HEAT_COOL; - this->custom_fan_mode = {"Auto Low"}; + this->set_custom_fan_mode_("Auto Low"); this->swing_mode = climate::CLIMATE_SWING_HORIZONTAL; this->preset = climate::CLIMATE_PRESET_AWAY; break; @@ -58,23 +58,19 @@ class DemoClimate : public climate::Climate, public Component { this->target_temperature_high = *call.get_target_temperature_high(); } if (call.get_fan_mode().has_value()) { - this->fan_mode = *call.get_fan_mode(); - this->custom_fan_mode.reset(); + this->set_fan_mode_(*call.get_fan_mode()); } if (call.get_swing_mode().has_value()) { this->swing_mode = *call.get_swing_mode(); } if (call.get_custom_fan_mode().has_value()) { - this->custom_fan_mode = *call.get_custom_fan_mode(); - this->fan_mode.reset(); + this->set_custom_fan_mode_(call.get_custom_fan_mode()->c_str()); } if (call.get_preset().has_value()) { - this->preset = *call.get_preset(); - this->custom_preset.reset(); + this->set_preset_(*call.get_preset()); } if (call.get_custom_preset().has_value()) { - this->custom_preset = *call.get_custom_preset(); - this->preset.reset(); + this->set_custom_preset_(call.get_custom_preset()->c_str()); } this->publish_state(); }