mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 15:35:59 -07:00
Merge branch 'integration' into memory_api
This commit is contained in:
@@ -25,7 +25,11 @@ void log_text_sensor(const char *tag, const char *prefix, const char *type, Text
|
||||
}
|
||||
|
||||
void TextSensor::publish_state(const std::string &state) {
|
||||
this->raw_state = 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;
|
||||
}
|
||||
|
||||
// Call raw callbacks (before filters)
|
||||
this->callbacks_.call_first(this->raw_count_, state);
|
||||
@@ -78,7 +82,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 { return this->raw_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;
|
||||
}
|
||||
void TextSensor::internal_send_state_to_frontend(const std::string &state) {
|
||||
this->state = state;
|
||||
this->set_has_state(true);
|
||||
|
||||
@@ -50,7 +50,6 @@ class TextSensor : public EntityBase, public EntityBase_DeviceClass {
|
||||
void add_on_raw_state_callback(std::function<void(std::string)> callback);
|
||||
|
||||
std::string state;
|
||||
std::string raw_state;
|
||||
|
||||
// ========== INTERNAL METHODS ==========
|
||||
// (In most use cases you won't need these)
|
||||
@@ -62,6 +61,10 @@ 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)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user