mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 10:36:01 +00:00
Fix Midea preset merge, fix get_supports_fan_modes precedence
- 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
This commit is contained in:
@@ -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_; }
|
||||
|
||||
|
||||
@@ -24,10 +24,22 @@ template<typename T> 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<const char *> 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;
|
||||
|
||||
Reference in New Issue
Block a user