6#ifdef USE_TEXT_SENSOR_FILTER
10#include <initializer_list>
17void log_text_sensor(
const char *tag,
const char *prefix,
const char *
type, TextSensor *obj);
19#define LOG_TEXT_SENSOR(prefix, type, obj) log_text_sensor(TAG, prefix, LOG_STR_LITERAL(type), obj)
21#define SUB_TEXT_SENSOR(name) \
23 text_sensor::TextSensor *name##_text_sensor_{nullptr}; \
26 void set_##name##_text_sensor(text_sensor::TextSensor *text_sensor) { this->name##_text_sensor_ = text_sensor; }
44#ifdef USE_TEXT_SENSOR_FILTER
49 void add_filters(std::initializer_list<Filter *> filters);
52 void set_filters(std::initializer_list<Filter *> filters);
63#ifdef USE_TEXT_SENSOR_FILTER
66 this->
callback_.add(std::forward<F>(callback));
81#ifdef USE_TEXT_SENSOR_FILTER
87#ifdef USE_TEXT_SENSOR_FILTER
Apply a filter to text sensor values such as to_upper.
void internal_send_state_to_frontend(const std::string &state)
void add_filter(Filter *filter)
Add a filter to the filter chain. Will be appended to the back.
const std::string & get_raw_state() const
Returns the raw (pre-filter) state.
void clear_filters()
Clear the entire filter chain.
void set_filters(std::initializer_list< Filter * > filters)
Clear the filters and replace them by filters.
Filter * filter_list_
Store all active filters.
void add_on_state_callback(F &&callback)
LazyCallbackManager< void(const std::string &)> raw_callback_
Storage for raw state callbacks.
LazyCallbackManager< void(const std::string &)> callback_
Storage for filtered state callbacks.
void add_on_raw_state_callback(F &&callback)
Add a callback that will be called every time the sensor sends a raw value.
const std::string & get_state() const
Getter-syntax for .state.
std::string raw_state_
Backing storage for the raw (pre-filter) value. Only used when a filter is attached.
void add_filters(std::initializer_list< Filter * > filters)
Add a list of vectors to the back of the filter chain.
void publish_state(const char *state)
void notify_frontend_()
Notify frontend that state has changed (assumes this->state is already set)
void publish_state(const std::string &state)
void log_text_sensor(const char *tag, const char *prefix, const char *type, TextSensor *obj)