mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
Move demo custom modes to setup(), simplify Midea frost protection
- Demo: custom fan modes and presets now set once in setup() instead of on every traits() call, matching bedjet/thermostat pattern - Midea: frost protection merge only calls get_traits() once (guarded by frost_protection_set_ flag), not on every status change
This commit is contained in:
@@ -16,6 +16,19 @@ class DemoClimate : public climate::Climate, public Component {
|
||||
public:
|
||||
void set_type(DemoClimateType type) { type_ = type; }
|
||||
void setup() override {
|
||||
// Set custom modes once during setup — stored on Climate base class, wired via get_traits()
|
||||
switch (type_) {
|
||||
case DemoClimateType::TYPE_1:
|
||||
break;
|
||||
case DemoClimateType::TYPE_2:
|
||||
this->set_supported_custom_fan_modes({"Auto Low", "Auto High"});
|
||||
this->set_supported_custom_presets({"My Preset"});
|
||||
break;
|
||||
case DemoClimateType::TYPE_3:
|
||||
this->set_supported_custom_fan_modes({"Auto Low", "Auto High"});
|
||||
break;
|
||||
}
|
||||
// Set initial state
|
||||
switch (type_) {
|
||||
case DemoClimateType::TYPE_1:
|
||||
this->current_temperature = 20.0;
|
||||
@@ -105,14 +118,13 @@ class DemoClimate : public climate::Climate, public Component {
|
||||
climate::CLIMATE_FAN_DIFFUSE,
|
||||
climate::CLIMATE_FAN_QUIET,
|
||||
});
|
||||
this->set_supported_custom_fan_modes({"Auto Low", "Auto High"});
|
||||
// Custom fan modes and presets are set once in setup()
|
||||
traits.set_supported_swing_modes({
|
||||
climate::CLIMATE_SWING_OFF,
|
||||
climate::CLIMATE_SWING_BOTH,
|
||||
climate::CLIMATE_SWING_VERTICAL,
|
||||
climate::CLIMATE_SWING_HORIZONTAL,
|
||||
});
|
||||
this->set_supported_custom_presets({"My Preset"});
|
||||
break;
|
||||
case DemoClimateType::TYPE_3:
|
||||
traits.add_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_TEMPERATURE |
|
||||
@@ -123,7 +135,7 @@ class DemoClimate : public climate::Climate, public Component {
|
||||
climate::CLIMATE_MODE_HEAT,
|
||||
climate::CLIMATE_MODE_HEAT_COOL,
|
||||
});
|
||||
this->set_supported_custom_fan_modes({"Auto Low", "Auto High"});
|
||||
// Custom fan modes are set once in setup()
|
||||
traits.set_supported_swing_modes({
|
||||
climate::CLIMATE_SWING_OFF,
|
||||
climate::CLIMATE_SWING_HORIZONTAL,
|
||||
|
||||
@@ -24,19 +24,20 @@ template<typename T> void update_property(T &property, const T &value, bool &fla
|
||||
}
|
||||
|
||||
void AirConditioner::on_status_change() {
|
||||
// Add frost protection custom preset once when autoconf completes (merge, don't overwrite)
|
||||
// Add frost protection custom preset once when autoconf completes
|
||||
if (this->base_.getAutoconfStatus() == dudanov::midea::AUTOCONF_OK &&
|
||||
this->base_.getCapabilities().supportFrostProtectionPreset() && !this->frost_protection_set_) {
|
||||
auto presets = this->get_traits().get_supported_custom_presets();
|
||||
// Read existing presets (set by codegen), append frost protection, write back
|
||||
const auto &existing = this->get_traits().get_supported_custom_presets();
|
||||
bool found = false;
|
||||
for (const char *p : presets) {
|
||||
for (const char *p : existing) {
|
||||
if (strcmp(p, Constants::FREEZE_PROTECTION) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
std::vector<const char *> merged(presets.begin(), presets.end());
|
||||
std::vector<const char *> merged(existing.begin(), existing.end());
|
||||
merged.push_back(Constants::FREEZE_PROTECTION);
|
||||
this->set_supported_custom_presets(merged);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user