15void log_sensor(
const char *tag,
const char *prefix,
const char *
type, Sensor *obj);
17#define LOG_SENSOR(prefix, type, obj) log_sensor(TAG, prefix, LOG_STR_LITERAL(type), obj)
19#define SUB_SENSOR(name) \
21 sensor::Sensor *name##_sensor_{nullptr}; \
24 void set_##name##_sensor(sensor::Sensor *sensor) { this->name##_sensor_ = sensor; }
80 void add_filters(
const std::vector<Filter *> &filters);
83 void set_filters(
const std::vector<Filter *> &filters);
Apply a filter to sensor values such as moving average.
Base-class for all sensors.
void set_state_class(StateClass state_class)
Manually set the state class.
void add_filter(Filter *filter)
Add a filter to the filter chain. Will be appended to the back.
void publish_state(float state)
Publish a new state to the front-end.
void internal_send_state_to_frontend(float state)
float get_raw_state() const
Getter-syntax for .raw_state.
void set_force_update(bool force_update)
Set force update mode.
CallbackManager< void(float)> callback_
Storage for filtered state callbacks.
void add_filters(const std::vector< Filter * > &filters)
Add a list of vectors to the back of the filter chain.
float get_state() const
Getter-syntax for .state.
void set_accuracy_decimals(int8_t accuracy_decimals)
Manually set the accuracy in decimals.
void set_filters(const std::vector< Filter * > &filters)
Clear the filters and replace them by filters.
void add_on_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time a filtered value arrives.
float state
This member variable stores the last state that has passed through all filters.
StateClass get_state_class()
Get the state class, using the manual override if set.
Filter * filter_list_
Store all active filters.
float raw_state
This member variable stores the current raw state of the sensor, without any filters applied.
int8_t get_accuracy_decimals()
Get the accuracy in decimals, using the manual override if set.
void clear_filters()
Clear the entire filter chain.
int8_t accuracy_decimals_
Accuracy in decimals (-1 = not set)
StateClass state_class_
State class (STATE_CLASS_NONE = not set)
bool get_force_update() const
Get whether force update mode is enabled.
struct esphome::sensor::Sensor::SensorFlags sensor_flags_
std::unique_ptr< CallbackManager< void(float)> > raw_callback_
Storage for raw state callbacks (lazy allocated).
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.
StateClass
Sensor state classes.
@ STATE_CLASS_TOTAL_INCREASING
@ STATE_CLASS_MEASUREMENT
void log_sensor(const char *tag, const char *prefix, const char *type, Sensor *obj)
const LogString * state_class_to_string(StateClass state_class)
Providing packet encoding functions for exchanging data with a remote host.
uint8_t has_state_class_override
uint8_t has_accuracy_override