ESPHome  2024.4.1
Public Member Functions | Protected Attributes
esphome::text_sensor::Filter Class Referenceabstract

Apply a filter to text sensor values such as to_upper. More...

#include <filter.h>

Inheritance diagram for esphome::text_sensor::Filter:
esphome::text_sensor::AppendFilter esphome::text_sensor::LambdaFilter esphome::text_sensor::MapFilter esphome::text_sensor::PrependFilter esphome::text_sensor::SubstituteFilter esphome::text_sensor::ToLowerFilter esphome::text_sensor::ToUpperFilter

Public Member Functions

virtual optional< std::string > new_value (std::string value)=0
 This will be called every time the filter receives a new value. More...
 
virtual void initialize (TextSensor *parent, Filter *next)
 Initialize this filter, please note this can be called more than once. More...
 
void input (const std::string &value)
 
void output (const std::string &value)
 

Protected Attributes

friend TextSensor
 
Filternext_ {nullptr}
 
TextSensorparent_ {nullptr}
 

Detailed Description

Apply a filter to text sensor values such as to_upper.

This class is purposefully kept quite simple, since more complicated filters should really be done with the filter sensor in Home Assistant.

Definition at line 20 of file filter.h.

Member Function Documentation

◆ initialize()

void esphome::text_sensor::Filter::initialize ( TextSensor parent,
Filter next 
)
virtual

Initialize this filter, please note this can be called more than once.

Definition at line 27 of file filter.cpp.

◆ input()

void esphome::text_sensor::Filter::input ( const std::string &  value)

Definition at line 12 of file filter.cpp.

◆ new_value()

virtual optional<std::string> esphome::text_sensor::Filter::new_value ( std::string  value)
pure virtual

This will be called every time the filter receives a new value.

It can return an empty optional to indicate that the filter chain should stop, otherwise the value in the filter will be passed down the chain.

Parameters
valueThe new value.
Returns
An optional string, the new value that should be pushed out.

Implemented in esphome::text_sensor::MapFilter, esphome::text_sensor::SubstituteFilter, esphome::text_sensor::PrependFilter, esphome::text_sensor::AppendFilter, esphome::text_sensor::ToLowerFilter, esphome::text_sensor::ToUpperFilter, and esphome::text_sensor::LambdaFilter.

◆ output()

void esphome::text_sensor::Filter::output ( const std::string &  value)

Definition at line 18 of file filter.cpp.

Field Documentation

◆ next_

Filter* esphome::text_sensor::Filter::next_ {nullptr}
protected

Definition at line 43 of file filter.h.

◆ parent_

TextSensor* esphome::text_sensor::Filter::parent_ {nullptr}
protected

Definition at line 44 of file filter.h.

◆ TextSensor

friend esphome::text_sensor::Filter::TextSensor
protected

Definition at line 41 of file filter.h.


The documentation for this class was generated from the following files: