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:
J. Nick Koston
2026-03-26 15:58:23 -10:00
parent a3f5458ae3
commit eaa7659285
2 changed files with 22 additions and 5 deletions
+8 -3
View File
@@ -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_; }
+14 -2
View File
@@ -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;