2#ifdef USE_TEXT_SENSOR_FILTER
16 ESP_LOGVV(TAG,
"Filter(%p)::input(%s)",
this,
value.c_str());
21 if (this->
next_ ==
nullptr) {
22 ESP_LOGVV(TAG,
"Filter(%p)::output(%s) -> SENSOR",
this,
value.c_str());
25 ESP_LOGVV(TAG,
"Filter(%p)::output(%s) -> %p",
this,
value.c_str(), this->next_);
30 ESP_LOGVV(TAG,
"Filter(%p)::initialize(parent=%p next=%p)",
this, parent,
next);
42 if (result.has_value()) {
43 ESP_LOGVV(TAG,
"LambdaFilter(%p)::new_value(%s) -> %s (continue)",
this,
value.c_str(), result->c_str());
44 value = std::move(*result);
47 ESP_LOGVV(TAG,
"LambdaFilter(%p)::new_value(%s) -> (stop)",
this,
value.c_str());
80 const size_t from_len = strlen(s->from);
81 const size_t to_len = strlen(s->to);
83 while ((
pos =
value.find(s->from,
pos, from_len)) != std::string::npos) {
84 value.replace(
pos, from_len, s->to, to_len);
94 if (value ==
m->from) {
105 const char *
const *prioritized) {
107 bool pass = last_input == 0 || now - last_input >= period;
108 for (
const char *
const *p = prioritized; !pass && p !=
nullptr && *p !=
nullptr; p++)
139 if (this->
next_ ==
nullptr) {
158 this->
send_(this->
last_.data(), this->last_.size());
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void enable_loop()
Enable this component's loop.
void disable_loop()
Disable this component's loop.
bool new_value(std::string &value) override
Apply a filter to text sensor values such as to_upper.
virtual bool new_value(std::string &value)=0
This will be called every time the filter receives a new value.
void output(std::string &value)
void input(std::string value)
virtual void initialize(TextSensor *parent, Filter *next)
Initialize this filter, please note this can be called more than once.
lambda_filter_t lambda_filter_
LambdaFilter(lambda_filter_t lambda_filter)
void set_lambda_filter(const lambda_filter_t &lambda_filter)
bool new_value(std::string &value) override
const lambda_filter_t & get_lambda_filter() const
bool new_value(std::string &value) override
const Substitution * mappings_
bool new_value(std::string &value) override
bool new_value(std::string &value) override
const Substitution * substitutions_
void internal_send_state_to_frontend(const std::string &state)
bool new_value(std::string &value) override
uint32_t min_time_between_inputs_
bool new_value(std::string &value) override
const char *const * prioritized_
bool new_value(std::string &value) override
uint32_t timeout_start_time_
virtual void send_timeout_value()=0
void send_(const char *text, size_t len)
Sends text; never moves a stored string on, so it keeps its buffer.
bool new_value(std::string &value) override
void send_timeout_value() override
const char *const * prioritized_
bool new_value(std::string &value) override
bool new_value(std::string &value) override
bool new_value(std::string &value) override
std::function< optional< std::string >(std::string)> lambda_filter_t
ESPHOME_LOG_TAG(TAG, "text_sensor.filter")
Application App
Global storage of Application pointer - only one Application can exist.