diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 33d5072d9c..90e37c8c59 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -410,8 +410,8 @@ uint16_t APIConnection::try_send_fan_state(EntityBase *entity, APIConnection *co } if (traits.supports_direction()) msg.direction = static_cast(fan->direction); - if (traits.supports_preset_modes()) - msg.set_preset_mode(StringRef(fan->preset_mode)); + if (traits.supports_preset_modes() && fan->has_preset_mode()) + msg.set_preset_mode(StringRef(fan->get_preset_mode())); return fill_and_encode_entity_state(fan, msg, FanStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } uint16_t APIConnection::try_send_fan_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size, diff --git a/esphome/components/fan/fan.cpp b/esphome/components/fan/fan.cpp index c4abab0b4a..cfc09f4d53 100644 --- a/esphome/components/fan/fan.cpp +++ b/esphome/components/fan/fan.cpp @@ -151,24 +151,12 @@ bool Fan::set_preset_mode_(const char *preset_mode) { return false; // Preset mode not supported or no change } this->preset_mode_ = validated; - // Keep deprecated member in sync during deprecation period -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - this->preset_mode = validated; -#pragma GCC diagnostic pop return true; } bool Fan::set_preset_mode_(const std::string &preset_mode) { return this->set_preset_mode_(preset_mode.c_str()); } -void Fan::clear_preset_mode_() { - this->preset_mode_ = nullptr; - // Keep deprecated member in sync during deprecation period -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - this->preset_mode.clear(); -#pragma GCC diagnostic pop -} +void Fan::clear_preset_mode_() { this->preset_mode_ = nullptr; } void Fan::add_on_state_callback(std::function &&callback) { this->state_callback_.add(std::move(callback)); } void Fan::publish_state() { diff --git a/esphome/components/fan/fan.h b/esphome/components/fan/fan.h index 16fe42f9f4..33e546b2bb 100644 --- a/esphome/components/fan/fan.h +++ b/esphome/components/fan/fan.h @@ -111,11 +111,6 @@ class Fan : public EntityBase { int speed{0}; /// The current direction of the fan FanDirection direction{FanDirection::FORWARD}; - // The current preset mode of the fan - // Deprecated: Use get_preset_mode() for reading and set_preset_mode_() for writing. Will be removed in 2026.5.0 - __attribute__((deprecated("Use get_preset_mode() for reading and set_preset_mode_() for writing instead of " - ".preset_mode. Will be removed in 2026.5.0"))); - std::string preset_mode{}; FanCall turn_on(); FanCall turn_off(); @@ -135,6 +130,9 @@ class Fan : public EntityBase { /// Get the current preset mode (returns pointer to string stored in traits, or nullptr if not set) const char *get_preset_mode() const { return this->preset_mode_; } + /// Check if a preset mode is currently active + bool has_preset_mode() const { return this->preset_mode_ != nullptr; } + protected: friend FanCall; friend struct FanRestoreState;