midea_ac: fix presets implementation (#2054)

This commit is contained in:
Sergey V. DUDANOV 2021-07-22 16:39:21 +04:00 committed by GitHub
parent 80949521b6
commit ba461e51a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 10 deletions

View file

@ -100,7 +100,7 @@ bool MideaAC::allow_preset(climate::ClimatePreset preset) const {
ESP_LOGD(TAG, "BOOST preset is only available in HEAT or COOL mode"); ESP_LOGD(TAG, "BOOST preset is only available in HEAT or COOL mode");
} }
break; break;
case climate::CLIMATE_PRESET_HOME: case climate::CLIMATE_PRESET_NONE:
return true; return true;
default: default:
break; break;
@ -191,7 +191,7 @@ climate::ClimateTraits MideaAC::traits() {
if (traits_swing_both_) if (traits_swing_both_)
traits.add_supported_swing_mode(climate::CLIMATE_SWING_BOTH); traits.add_supported_swing_mode(climate::CLIMATE_SWING_BOTH);
traits.set_supported_presets({ traits.set_supported_presets({
climate::CLIMATE_PRESET_HOME, climate::CLIMATE_PRESET_NONE,
}); });
if (traits_preset_eco_) if (traits_preset_eco_)
traits.add_supported_preset(climate::CLIMATE_PRESET_ECO); traits.add_supported_preset(climate::CLIMATE_PRESET_ECO);

View file

@ -86,18 +86,17 @@ void PropertiesFrame::set_mode(climate::ClimateMode mode) {
} }
optional<climate::ClimatePreset> PropertiesFrame::get_preset() const { optional<climate::ClimatePreset> PropertiesFrame::get_preset() const {
if (this->get_eco_mode()) { if (this->get_eco_mode())
return climate::CLIMATE_PRESET_ECO; return climate::CLIMATE_PRESET_ECO;
} else if (this->get_sleep_mode()) { if (this->get_sleep_mode())
return climate::CLIMATE_PRESET_SLEEP; return climate::CLIMATE_PRESET_SLEEP;
} else if (this->get_turbo_mode()) { if (this->get_turbo_mode())
return climate::CLIMATE_PRESET_BOOST; return climate::CLIMATE_PRESET_BOOST;
} else { return climate::CLIMATE_PRESET_NONE;
return climate::CLIMATE_PRESET_HOME;
}
} }
void PropertiesFrame::set_preset(climate::ClimatePreset preset) { void PropertiesFrame::set_preset(climate::ClimatePreset preset) {
this->clear_presets();
switch (preset) { switch (preset) {
case climate::CLIMATE_PRESET_ECO: case climate::CLIMATE_PRESET_ECO:
this->set_eco_mode(true); this->set_eco_mode(true);
@ -113,14 +112,21 @@ void PropertiesFrame::set_preset(climate::ClimatePreset preset) {
} }
} }
void PropertiesFrame::clear_presets() {
this->set_eco_mode(false);
this->set_sleep_mode(false);
this->set_turbo_mode(false);
this->set_freeze_protection_mode(false);
}
bool PropertiesFrame::is_custom_preset() const { return this->get_freeze_protection_mode(); } bool PropertiesFrame::is_custom_preset() const { return this->get_freeze_protection_mode(); }
const std::string &PropertiesFrame::get_custom_preset() const { return midea_ac::MIDEA_FREEZE_PROTECTION_PRESET; }; const std::string &PropertiesFrame::get_custom_preset() const { return midea_ac::MIDEA_FREEZE_PROTECTION_PRESET; };
void PropertiesFrame::set_custom_preset(const std::string &preset) { void PropertiesFrame::set_custom_preset(const std::string &preset) {
if (preset == MIDEA_FREEZE_PROTECTION_PRESET) { this->clear_presets();
if (preset == MIDEA_FREEZE_PROTECTION_PRESET)
this->set_freeze_protection_mode(true); this->set_freeze_protection_mode(true);
}
} }
bool PropertiesFrame::is_custom_fan_mode() const { bool PropertiesFrame::is_custom_fan_mode() const {

View file

@ -115,6 +115,7 @@ class PropertiesFrame : public midea_dongle::BaseFrame {
/* PRESET */ /* PRESET */
optional<climate::ClimatePreset> get_preset() const; optional<climate::ClimatePreset> get_preset() const;
void set_preset(climate::ClimatePreset preset); void set_preset(climate::ClimatePreset preset);
void clear_presets();
bool is_custom_preset() const; bool is_custom_preset() const;
const std::string &get_custom_preset() const; const std::string &get_custom_preset() const;