10static const char *
const TAG =
"text_sensor";
18 LOG_ENTITY_DEVICE_CLASS(tag, prefix, *obj);
19 LOG_ENTITY_ICON(tag, prefix, *obj);
30 if (len != this->state.size() || memcmp(
state, this->state.data(),
len) != 0) {
34 ESP_LOGV(TAG,
"'%s': Received new state %s", this->
name_.
c_str(), this->state.c_str());
38#pragma GCC diagnostic push
39#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
41 if (len != this->raw_state.size() || memcmp(
state, this->raw_state.data(),
len) != 0) {
45 ESP_LOGV(TAG,
"'%s': Received new state %s", this->
name_.
c_str(), this->raw_state.c_str());
47#pragma GCC diagnostic pop
54 ESP_LOGVV(TAG,
"TextSensor(%p)::add_filter(%p)",
this, filter);
59 while (last_filter->
next_ !=
nullptr)
60 last_filter = last_filter->
next_;
66 for (
Filter *filter : filters) {
76 ESP_LOGVV(TAG,
"TextSensor(%p)::clear_filters()",
this);
94#pragma GCC diagnostic push
95#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
96 return this->raw_state;
97#pragma GCC diagnostic pop
105 if (
len != this->state.size() || memcmp(
state, this->state.data(),
len) != 0) {
113 ESP_LOGD(TAG,
"'%s' >> '%s'", this->
name_.
c_str(), this->state.c_str());
115#if defined(USE_TEXT_SENSOR) && defined(USE_CONTROLLER_REGISTRY)
static void notify_text_sensor_update(text_sensor::TextSensor *obj)
const StringRef & get_name() const
void set_has_state(bool state)
constexpr const char * c_str() const
Apply a filter to text sensor values such as to_upper.
void input(std::string value)
virtual void initialize(TextSensor *parent, Filter *next)
Initialize this filter, please note this can be called more than once.
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
Getter-syntax for .raw_state.
void add_on_state_callback(std::function< void(const std::string &)> callback)
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.
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(std::function< void(const std::string &)> 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.
void add_filters(std::initializer_list< Filter * > filters)
Add a list of vectors to the back of the filter chain.
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)
Providing packet encoding functions for exchanging data with a remote host.