Merge remote-tracking branch 'origin/text-sensor-guard-raw-callback' into integration

This commit is contained in:
J. Nick Koston
2026-03-22 18:47:25 -10:00
2 changed files with 11 additions and 1 deletions
@@ -31,7 +31,9 @@ void TextSensor::publish_state(const char *state, size_t len) {
if (len != this->state.size() || memcmp(state, this->state.data(), len) != 0) {
this->state.assign(state, len);
}
#ifdef USE_TEXT_SENSOR_FILTER
this->raw_callback_.call(this->state);
#endif
ESP_LOGV(TAG, "'%s': Received new state %s", this->name_.c_str(), this->state.c_str());
this->notify_frontend_();
#ifdef USE_TEXT_SENSOR_FILTER
+9 -1
View File
@@ -64,8 +64,14 @@ class TextSensor : public EntityBase {
template<typename F> void add_on_state_callback(F &&callback) { this->callback_.add(std::forward<F>(callback)); }
/// Add a callback that will be called every time the sensor sends a raw value.
/// When USE_TEXT_SENSOR_FILTER is not enabled, delegates to the regular callback
/// since raw state equals filtered state without filter support compiled in.
template<typename F> void add_on_raw_state_callback(F &&callback) {
#ifdef USE_TEXT_SENSOR_FILTER
this->raw_callback_.add(std::forward<F>(callback));
#else
this->callback_.add(std::forward<F>(callback));
#endif
}
// ========== INTERNAL METHODS ==========
@@ -77,8 +83,10 @@ class TextSensor : public EntityBase {
protected:
/// Notify frontend that state has changed (assumes this->state is already set)
void notify_frontend_();
#ifdef USE_TEXT_SENSOR_FILTER
LazyCallbackManager<void(const std::string &)> raw_callback_; ///< Storage for raw state callbacks.
LazyCallbackManager<void(const std::string &)> callback_; ///< Storage for filtered state callbacks.
#endif
LazyCallbackManager<void(const std::string &)> callback_; ///< Storage for filtered state callbacks.
#ifdef USE_TEXT_SENSOR_FILTER
Filter *filter_list_{nullptr}; ///< Store all active filters.