Merge branch 'give_six_months_for_text_sensor_raw_state' into integration

This commit is contained in:
J. Nick Koston
2025-12-01 23:37:09 -06:00
2 changed files with 17 additions and 12 deletions

View File

@@ -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
// Call raw callbacks (before filters)
this->callbacks_.call_first(this->raw_count_, state);
@@ -83,9 +83,11 @@ void TextSensor::add_on_raw_state_callback(std::function<void(std::string)> 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;

View File

@@ -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)
@@ -61,10 +68,6 @@ class TextSensor : public EntityBase, public EntityBase_DeviceClass {
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_;
uint8_t raw_count_{0}; ///< Number of raw callbacks (partition point in callbacks_ vector)
};