15 LOG_ENTITY_DEVICE_CLASS(
tag, prefix, *obj);
16 LOG_ENTITY_ICON(
tag, prefix, *obj);
20#ifdef USE_TEXT_SENSOR_FILTER
25 if (len != this->state.size() || memcmp(
state, this->state.data(),
len) != 0) {
28#ifdef USE_TEXT_SENSOR_FILTER
31 ESP_LOGV(TAG,
"'%s': Received new state %s", LOG_STR_ARG(this->
get_log_name()), this->state.c_str());
33#ifdef USE_TEXT_SENSOR_FILTER
50 strncpy_P(buf,
reinterpret_cast<PGM_P
>(
state),
sizeof(buf));
51 buf[
sizeof(buf) - 1] =
'\0';
56#ifdef USE_TEXT_SENSOR_FILTER
58 ESP_LOGVV(TAG,
"TextSensor(%p)::add_filter(%p)",
this, filter);
68 for (
Filter *filter : filters) {
78 ESP_LOGVV(TAG,
"TextSensor(%p)::clear_filters()",
this);
82#ifdef USE_TEXT_SENSOR_FILTER_RESET
85 if (filters ==
nullptr)
95 if (filters ==
nullptr)
109#ifdef USE_TEXT_SENSOR_FILTER
118 if (len != this->state.size() || memcmp(
state, this->state.data(),
len) != 0) {
126 ESP_LOGV(TAG,
"'%s' >> '%s'", LOG_STR_ARG(this->
get_log_name()), this->
state.c_str());
128#if defined(USE_TEXT_SENSOR) && defined(USE_CONTROLLER_REGISTRY)
129 ControllerRegistry::notify_text_sensor_update(
this);
Node * chain_last_()
Only for a chain that ends in its owner, never in nullptr.
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
void set_has_state(bool state)
Apply a filter to text sensor values such as to_upper.
void input(std::string value)
virtual void initialize(TextSensor *parent, Filter *next)
Put this filter in its state before the first value.
void reset_chain()
Re-initialize this filter and every filter after it, so they behave as at boot.
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.
LazyCallbackManager< void(const std::string &)> raw_callback_
Storage for raw state callbacks.
LazyCallbackManager< void(const std::string &)> callback_
Storage for filtered state callbacks.
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.
Filter * detach_filters()
Reset the filter chain and take it out of use, so values publish unfiltered.
void notify_frontend_()
Notify frontend that state has changed (assumes this->state is already set)
void attach_filters(Filter *filters)
Put back a chain from detach_filters() and run the current state through it, without calling the raw ...
void publish_state(const std::string &state)
ESPHOME_LOG_TAG(TAG, "text_sensor.filter")
void log_text_sensor(const char *tag, const char *prefix, const char *type, TextSensor *obj)
bool log_entity_header(const char *tag, const char *prefix, const char *type, const EntityBase *obj)
Log "<prefix><type> '<name>'" for a dump_config header; returns false when obj is null.
const __FlashStringHelper * ProgmemStr