mirror of
https://github.com/esphome/esphome.git
synced 2026-10-05 10:31:29 +00:00
Merge branch 'give_six_months_for_text_sensor_raw_state' into integration
This commit is contained in:
@@ -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) {
|
void TextSensor::publish_state(const std::string &state) {
|
||||||
// Only store raw_state_ separately when filters exist
|
// Suppress deprecation warning - we need to populate raw_state for backwards compatibility
|
||||||
// When no filters, raw_state == state, so we avoid the duplicate storage
|
#pragma GCC diagnostic push
|
||||||
if (this->filter_list_ != nullptr) {
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
this->raw_state_ = state;
|
this->raw_state = state;
|
||||||
}
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
// Call raw callbacks (before filters)
|
// Call raw callbacks (before filters)
|
||||||
this->callbacks_.call_first(this->raw_count_, state);
|
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_state() const { return this->state; }
|
||||||
std::string TextSensor::get_raw_state() const {
|
std::string TextSensor::get_raw_state() const {
|
||||||
// When no filters exist, raw_state == state, so return state to avoid
|
// Suppress deprecation warning - get_raw_state() is the replacement API
|
||||||
// requiring separate storage
|
#pragma GCC diagnostic push
|
||||||
return this->filter_list_ != nullptr ? this->raw_state_ : this->state;
|
#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) {
|
void TextSensor::internal_send_state_to_frontend(const std::string &state) {
|
||||||
this->state = state;
|
this->state = state;
|
||||||
|
|||||||
@@ -51,6 +51,13 @@ class TextSensor : public EntityBase, public EntityBase_DeviceClass {
|
|||||||
|
|
||||||
std::string state;
|
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 ==========
|
// ========== INTERNAL METHODS ==========
|
||||||
// (In most use cases you won't need these)
|
// (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.
|
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)
|
uint8_t raw_count_{0}; ///< Number of raw callbacks (partition point in callbacks_ vector)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user