7 static const char *
const TAG =
"sensor";
10 switch (state_class) {
14 return "total_increasing";
43 ESP_LOGV(TAG,
"'%s': Received new state %f", this->
name_.
c_str(),
state);
60 ESP_LOGVV(TAG,
"Sensor(%p)::add_filter(%p)",
this, filter);
65 while (last_filter->
next_ !=
nullptr)
66 last_filter = last_filter->
next_;
72 for (
Filter *filter : filters) {
82 ESP_LOGVV(TAG,
"Sensor(%p)::clear_filters()",
this);
93 ESP_LOGD(TAG,
"'%s': Sending state %.5f %s with %d decimals of accuracy", this->
get_name().c_str(), state,
void add_on_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time a filtered value arrives.
void clear_filters()
Clear the entire filter chain.
CallbackManager< void(float)> raw_callback_
Storage for raw state callbacks.
void set_filters(const std::vector< Filter *> &filters)
Clear the filters and replace them by filters.
optional< int8_t > accuracy_decimals_
Accuracy in decimals override.
void add_on_raw_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time the sensor sends a raw value.
float raw_state
This member variable stores the current raw state of the sensor, without any filters applied...
void add_filter(Filter *filter)
Add a filter to the filter chain. Will be appended to the back.
virtual std::string unique_id()
Override this method to set the unique ID of this sensor.
void set_accuracy_decimals(int8_t accuracy_decimals)
Manually set the accuracy in decimals.
float state
This member variable stores the last state that has passed through all filters.
std::string state_class_to_string(StateClass state_class)
StateClass
Sensor state classes.
void publish_state(float state)
Publish a new state to the front-end.
std::string get_unit_of_measurement()
Get the unit of measurement, using the manual override if set.
virtual void initialize(Sensor *parent, Filter *next)
Initialize this filter, please note this can be called more than once.
CallbackManager< void(float)> callback_
Storage for filtered state callbacks.
StateClass get_state_class()
Get the state class, using the manual override if set.
float get_raw_state() const
Getter-syntax for .raw_state.
constexpr const char * c_str() const
void add_filters(const std::vector< Filter *> &filters)
Add a list of vectors to the back of the filter chain.
Filter * filter_list_
Store all active filters.
float get_state() const
Getter-syntax for .state.
void internal_send_state_to_frontend(float state)
Apply a filter to sensor values such as moving average.
Implementation of SPI Controller mode.
bool has_state() const
Return whether this sensor has gotten a full state (that passed through all filters) yet...
void set_state_class(StateClass state_class)
Manually set the state class.
int8_t get_accuracy_decimals()
Get the accuracy in decimals, using the manual override if set.
optional< StateClass > state_class_
State class override.
esphome::sensor::Sensor * sensor
const StringRef & get_name() const