From 9f5e04c3d3a045bbca735843590f1a402e491449 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 1 Dec 2025 22:36:03 -0600 Subject: [PATCH] [text_sensor] Add deprecation warning for raw_state member access --- esphome/components/text_sensor/text_sensor.cpp | 18 ++++++++++-------- esphome/components/text_sensor/text_sensor.h | 11 +++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/esphome/components/text_sensor/text_sensor.cpp b/esphome/components/text_sensor/text_sensor.cpp index d984e78b2a..51923ebd96 100644 --- a/esphome/components/text_sensor/text_sensor.cpp +++ b/esphome/components/text_sensor/text_sensor.cpp @@ -25,11 +25,11 @@ void log_text_sensor(const char *tag, const char *prefix, const char *type, Text } void TextSensor::publish_state(const std::string &state) { - // Only store raw_state_ separately when filters exist - // When no filters, raw_state == state, so we avoid the duplicate storage - if (this->filter_list_ != nullptr) { - this->raw_state_ = state; - } +// Suppress deprecation warning - we need to populate raw_state for backwards compatibility +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + this->raw_state = state; +#pragma GCC diagnostic pop if (this->raw_callback_) { this->raw_callback_->call(state); } @@ -85,9 +85,11 @@ void TextSensor::add_on_raw_state_callback(std::function call std::string TextSensor::get_state() const { return this->state; } std::string TextSensor::get_raw_state() const { - // When no filters exist, raw_state == state, so return state to avoid - // requiring separate storage - return this->filter_list_ != nullptr ? this->raw_state_ : this->state; +// Suppress deprecation warning - get_raw_state() is the replacement API +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + return this->raw_state; +#pragma GCC diagnostic pop } void TextSensor::internal_send_state_to_frontend(const std::string &state) { this->state = state; diff --git a/esphome/components/text_sensor/text_sensor.h b/esphome/components/text_sensor/text_sensor.h index fcfbed2fbc..7217806a55 100644 --- a/esphome/components/text_sensor/text_sensor.h +++ b/esphome/components/text_sensor/text_sensor.h @@ -51,6 +51,13 @@ class TextSensor : public EntityBase, public EntityBase_DeviceClass { std::string state; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + /// @deprecated Use get_raw_state() instead. This member will be removed in ESPHome 2026.6.0. + ESPDEPRECATED("Use get_raw_state() instead of .raw_state. Will be removed in 2026.6.0", "2025.12.0") + std::string raw_state; +#pragma GCC diagnostic pop + // ========== INTERNAL METHODS ========== // (In most use cases you won't need these) @@ -62,10 +69,6 @@ class TextSensor : public EntityBase, public EntityBase_DeviceClass { CallbackManager callback_; ///< Storage for filtered state callbacks. Filter *filter_list_{nullptr}; ///< Store all active filters. - - /// Raw state (before filters). Only populated when filters are configured. - /// When no filters exist, get_raw_state() returns state directly. - std::string raw_state_; }; } // namespace text_sensor