1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-27 13:13:50 +00:00

Rework climate traits (#1941)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Otto Winter
2021-06-21 21:17:01 +02:00
committed by Jesse Hills
parent e20ec00071
commit d4eb0f1655
24 changed files with 393 additions and 546 deletions

View File

@@ -167,24 +167,38 @@ climate::ClimateTraits MideaAC::traits() {
traits.set_visual_min_temperature(17);
traits.set_visual_max_temperature(30);
traits.set_visual_temperature_step(0.5);
traits.set_supports_heat_cool_mode(true);
traits.set_supports_cool_mode(true);
traits.set_supports_dry_mode(true);
traits.set_supports_heat_mode(true);
traits.set_supports_fan_only_mode(true);
traits.set_supports_fan_mode_auto(true);
traits.set_supports_fan_mode_low(true);
traits.set_supports_fan_mode_medium(true);
traits.set_supports_fan_mode_high(true);
traits.set_supported_modes({
climate::CLIMATE_MODE_OFF,
climate::CLIMATE_MODE_HEAT_COOL,
climate::CLIMATE_MODE_COOL,
climate::CLIMATE_MODE_DRY,
climate::CLIMATE_MODE_HEAT,
climate::CLIMATE_MODE_FAN_ONLY,
});
traits.set_supported_fan_modes({
climate::CLIMATE_FAN_AUTO,
climate::CLIMATE_FAN_LOW,
climate::CLIMATE_FAN_MEDIUM,
climate::CLIMATE_FAN_HIGH,
});
traits.set_supported_custom_fan_modes(this->traits_custom_fan_modes_);
traits.set_supports_swing_mode_off(true);
traits.set_supports_swing_mode_vertical(true);
traits.set_supports_swing_mode_horizontal(this->traits_swing_horizontal_);
traits.set_supports_swing_mode_both(this->traits_swing_both_);
traits.set_supports_preset_home(true);
traits.set_supports_preset_eco(this->traits_preset_eco_);
traits.set_supports_preset_sleep(this->traits_preset_sleep_);
traits.set_supports_preset_boost(this->traits_preset_boost_);
traits.set_supported_swing_modes({
climate::CLIMATE_SWING_OFF,
climate::CLIMATE_SWING_VERTICAL,
});
if (traits_swing_horizontal_)
traits.add_supported_swing_mode(climate::CLIMATE_SWING_HORIZONTAL);
if (traits_swing_both_)
traits.add_supported_swing_mode(climate::CLIMATE_SWING_BOTH);
traits.set_supported_presets({
climate::CLIMATE_PRESET_HOME,
});
if (traits_preset_eco_)
traits.add_supported_preset(climate::CLIMATE_PRESET_ECO);
if (traits_preset_sleep_)
traits.add_supported_preset(climate::CLIMATE_PRESET_SLEEP);
if (traits_preset_boost_)
traits.add_supported_preset(climate::CLIMATE_PRESET_BOOST);
traits.set_supported_custom_presets(this->traits_custom_presets_);
traits.set_supports_current_temperature(true);
return traits;

View File

@@ -1,9 +1,9 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/midea_dongle/midea_dongle.h"
#include "esphome/components/climate/climate.h"
#include "esphome/components/midea_dongle/midea_dongle.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/core/component.h"
#include "midea_frame.h"
namespace esphome {
@@ -26,10 +26,12 @@ class MideaAC : public midea_dongle::MideaAppliance, public climate::Climate, pu
void set_preset_sleep(bool state) { this->traits_preset_sleep_ = state; }
void set_preset_boost(bool state) { this->traits_preset_boost_ = state; }
bool allow_preset(climate::ClimatePreset preset) const;
void set_custom_fan_modes(std::vector<std::string> custom_fan_modes) {
this->traits_custom_fan_modes_ = custom_fan_modes;
void set_custom_fan_modes(std::set<std::string> custom_fan_modes) {
this->traits_custom_fan_modes_ = std::move(custom_fan_modes);
}
void set_custom_presets(std::set<std::string> custom_presets) {
this->traits_custom_presets_ = std::move(custom_presets);
}
void set_custom_presets(std::vector<std::string> custom_presets) { this->traits_custom_presets_ = custom_presets; }
bool allow_custom_preset(const std::string &custom_preset) const;
protected:
@@ -53,8 +55,8 @@ class MideaAC : public midea_dongle::MideaAppliance, public climate::Climate, pu
bool traits_preset_eco_{false};
bool traits_preset_sleep_{false};
bool traits_preset_boost_{false};
std::vector<std::string> traits_custom_fan_modes_{{}};
std::vector<std::string> traits_custom_presets_{{}};
std::set<std::string> traits_custom_fan_modes_{{}};
std::set<std::string> traits_custom_presets_{{}};
};
} // namespace midea_ac