2 #include "text_sensor.h" 7 namespace text_sensor {
9 static const char *
const TAG =
"text_sensor.filter";
13 ESP_LOGVV(TAG,
"Filter(%p)::input(%s)",
this, value.c_str());
19 if (this->
next_ ==
nullptr) {
20 ESP_LOGVV(TAG,
"Filter(%p)::output(%s) -> SENSOR",
this, value.c_str());
23 ESP_LOGVV(TAG,
"Filter(%p)::output(%s) -> %p",
this, value.c_str(), this->
next_);
28 ESP_LOGVV(TAG,
"Filter(%p)::initialize(parent=%p next=%p)",
this, parent, next);
40 ESP_LOGVV(TAG,
"LambdaFilter(%p)::new_value(%s) -> %s",
this, value.c_str(), it.value_or(
"").c_str());
67 for (
size_t i = 0; i < this->from_strings_.size(); i++) {
68 while ((pos = value.find(this->from_strings_[i])) != std::string::npos)
69 value.replace(pos, this->from_strings_[i].size(), this->to_strings_[i]);
76 auto item = mappings_.find(value);
77 return item == mappings_.end() ? value : item->second;
void set_lambda_filter(const lambda_filter_t &lambda_filter)
const lambda_filter_t & get_lambda_filter() const
void input(const std::string &value)
lambda_filter_t lambda_filter_
virtual optional< std::string > new_value(std::string value)=0
This will be called every time the filter receives a new value.
std::function< optional< std::string >(std::string)> lambda_filter_t
optional< std::string > new_value(std::string value) override
void internal_send_state_to_frontend(const std::string &state)
optional< std::string > new_value(std::string value) override
virtual void initialize(TextSensor *parent, Filter *next)
Initialize this filter, please note this can be called more than once.
void output(const std::string &value)
optional< std::string > new_value(std::string value) override
optional< std::string > new_value(std::string value) override
optional< std::string > new_value(std::string value) override
Implementation of SPI Controller mode.
optional< std::string > new_value(std::string value) override
LambdaFilter(lambda_filter_t lambda_filter)
Apply a filter to text sensor values such as to_upper.
optional< std::string > new_value(std::string value) override