From eaa76592859ca4f385e48beb24c6618deab693b2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Mar 2026 15:58:23 -1000 Subject: [PATCH] Fix Midea preset merge, fix get_supports_fan_modes precedence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Midea: merge frost protection into existing custom presets instead of overwriting (fixes potential loss of user-configured presets) - get_supports_fan_modes(): use same precedence as getter — if pointer is set, only check pointer; fall back to compat only when unset --- esphome/components/climate/climate_traits.h | 11 ++++++++--- esphome/components/midea/air_conditioner.cpp | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/esphome/components/climate/climate_traits.h b/esphome/components/climate/climate_traits.h index d31de34e24..65cae3a077 100644 --- a/esphome/components/climate/climate_traits.h +++ b/esphome/components/climate/climate_traits.h @@ -147,9 +147,14 @@ class ClimateTraits { void add_supported_fan_mode(ClimateFanMode mode) { this->supported_fan_modes_.insert(mode); } bool supports_fan_mode(ClimateFanMode fan_mode) const { return this->supported_fan_modes_.count(fan_mode); } bool get_supports_fan_modes() const { - return !this->supported_fan_modes_.empty() || - (this->supported_custom_fan_modes_ && !this->supported_custom_fan_modes_->empty()) || - !this->compat_custom_fan_modes_.empty(); // Compat: remove in 2026.11.0 + if (!this->supported_fan_modes_.empty()) { + return true; + } + // Same precedence as get_supported_custom_fan_modes() getter + if (this->supported_custom_fan_modes_) { + return !this->supported_custom_fan_modes_->empty(); + } + return !this->compat_custom_fan_modes_.empty(); // Compat: remove in 2026.11.0 } const ClimateFanModeMask &get_supported_fan_modes() const { return this->supported_fan_modes_; } diff --git a/esphome/components/midea/air_conditioner.cpp b/esphome/components/midea/air_conditioner.cpp index 77bec5c7a2..2a9a5e9902 100644 --- a/esphome/components/midea/air_conditioner.cpp +++ b/esphome/components/midea/air_conditioner.cpp @@ -24,10 +24,22 @@ template void update_property(T &property, const T &value, bool &fla } void AirConditioner::on_status_change() { - // Set frost protection custom preset once when autoconf completes + // Add frost protection custom preset once when autoconf completes (merge, don't overwrite) if (this->base_.getAutoconfStatus() == dudanov::midea::AUTOCONF_OK && this->base_.getCapabilities().supportFrostProtectionPreset() && !this->frost_protection_set_) { - this->set_supported_custom_presets({Constants::FREEZE_PROTECTION}); + auto presets = this->get_traits().get_supported_custom_presets(); + bool found = false; + for (const char *p : presets) { + if (strcmp(p, Constants::FREEZE_PROTECTION) == 0) { + found = true; + break; + } + } + if (!found) { + std::vector merged(presets.begin(), presets.end()); + merged.push_back(Constants::FREEZE_PROTECTION); + this->set_supported_custom_presets(merged); + } this->frost_protection_set_ = true; } bool need_publish = false;