1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-03 08:31:47 +00:00

Merge branch 'fan_no_double_storage' into integration

This commit is contained in:
J. Nick Koston
2025-11-02 20:21:57 -06:00
3 changed files with 6 additions and 3 deletions

View File

@@ -215,8 +215,9 @@ class FanPresetSetTrigger : public Trigger<std::string> {
const auto *preset_mode = state->get_preset_mode();
auto should_trigger = preset_mode != this->last_preset_mode_;
this->last_preset_mode_ = preset_mode;
if (should_trigger && preset_mode != nullptr) {
this->trigger(preset_mode);
if (should_trigger) {
// Trigger with empty string when nullptr to maintain backward compatibility
this->trigger(preset_mode != nullptr ? preset_mode : "");
}
});
this->last_preset_mode_ = state->get_preset_mode();

View File

@@ -177,7 +177,7 @@ void Fan::publish_state() {
ESP_LOGD(TAG, " Direction: %s", LOG_STR_ARG(fan_direction_to_string(this->direction)));
}
const char *preset = this->get_preset_mode();
if (traits.supports_preset_modes() && preset != nullptr) {
if (preset != nullptr) {
ESP_LOGD(TAG, " Preset Mode: %s", preset);
}
this->state_callback_.call();

View File

@@ -156,6 +156,8 @@ class Fan : public EntityBase {
CallbackManager<void()> state_callback_{};
ESPPreferenceObject rtc_;
FanRestoreMode restore_mode_;
private:
const char *preset_mode_{nullptr};
};