8#include <initializer_list>
12namespace text_sensor {
14void log_text_sensor(
const char *tag,
const char *prefix,
const char *
type, TextSensor *obj);
16#define LOG_TEXT_SENSOR(prefix, type, obj) log_text_sensor(TAG, prefix, LOG_STR_LITERAL(type), obj)
18#define SUB_TEXT_SENSOR(name) \
20 text_sensor::TextSensor *name##_text_sensor_{nullptr}; \
23 void set_##name##_text_sensor(text_sensor::TextSensor *text_sensor) { this->name##_text_sensor_ = text_sensor; }
29#pragma GCC diagnostic push
30#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
32 ESPDEPRECATED(
"Use get_raw_state() instead of .raw_state. Will be removed in 2026.6.0",
"2025.12.0")
33 std::
string raw_state;
37#pragma GCC diagnostic pop
50 void add_filters(std::initializer_list<Filter *> filters);
53 void set_filters(std::initializer_list<Filter *> filters);
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.
CallbackManager< void(std::string)> callback_
Storage for filtered state callbacks.
std::unique_ptr< CallbackManager< void(std::string)> > raw_callback_
Storage for raw state callbacks (lazy allocated).
void clear_filters()
Clear the entire filter chain.
void set_filters(std::initializer_list< Filter * > filters)
Clear the filters and replace them by filters.
std::string get_state() const
Getter-syntax for .state.
Filter * filter_list_
Store all active filters.
void add_on_raw_state_callback(std::function< void(std::string)> callback)
Add a callback that will be called every time the sensor sends a raw value.
void add_on_state_callback(std::function< void(std::string)> callback)
void add_filters(std::initializer_list< Filter * > filters)
Add a list of vectors to the back of the filter chain.
std::string get_raw_state() const
Getter-syntax for .raw_state.
void publish_state(const std::string &state)
void log_text_sensor(const char *tag, const char *prefix, const char *type, TextSensor *obj)
Providing packet encoding functions for exchanging data with a remote host.
struct ESPDEPRECATED("Use std::index_sequence instead. Removed in 2026.6.0", "2025.12.0") seq