midea_ac: fix presets implementation (#2054)

This commit is contained in:
Sergey V. DUDANOV 2021-07-22 16:39:21 +04:00 committed by Jesse Hills
parent caa651e55b
commit 1efabd27d8
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
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");
}
break;
case climate::CLIMATE_PRESET_HOME:
case climate::CLIMATE_PRESET_NONE:
return true;
default:
break;
@ -191,7 +191,7 @@ climate::ClimateTraits MideaAC::traits() {
if (traits_swing_both_)
traits.add_supported_swing_mode(climate::CLIMATE_SWING_BOTH);
traits.set_supported_presets({
climate::CLIMATE_PRESET_HOME,
climate::CLIMATE_PRESET_NONE,
});
if (traits_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 {
if (this->get_eco_mode()) {
if (this->get_eco_mode())
return climate::CLIMATE_PRESET_ECO;
} else if (this->get_sleep_mode()) {
if (this->get_sleep_mode())
return climate::CLIMATE_PRESET_SLEEP;
} else if (this->get_turbo_mode()) {
if (this->get_turbo_mode())
return climate::CLIMATE_PRESET_BOOST;
} else {
return climate::CLIMATE_PRESET_HOME;
}
return climate::CLIMATE_PRESET_NONE;
}
void PropertiesFrame::set_preset(climate::ClimatePreset preset) {
this->clear_presets();
switch (preset) {
case climate::CLIMATE_PRESET_ECO:
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(); }
const std::string &PropertiesFrame::get_custom_preset() const { return midea_ac::MIDEA_FREEZE_PROTECTION_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);
}
}
bool PropertiesFrame::is_custom_fan_mode() const {

View File

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