14 #define LOG_SENSOR(prefix, type, obj) \ 15 if ((obj) != nullptr) { \ 16 ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \ 17 if (!(obj)->get_device_class().empty()) { \ 18 ESP_LOGCONFIG(TAG, "%s Device Class: '%s'", prefix, (obj)->get_device_class().c_str()); \ 20 ESP_LOGCONFIG(TAG, "%s State Class: '%s'", prefix, state_class_to_string((obj)->get_state_class()).c_str()); \ 21 ESP_LOGCONFIG(TAG, "%s Unit of Measurement: '%s'", prefix, (obj)->get_unit_of_measurement().c_str()); \ 22 ESP_LOGCONFIG(TAG, "%s Accuracy Decimals: %d", prefix, (obj)->get_accuracy_decimals()); \ 23 if (!(obj)->get_icon().empty()) { \ 24 ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \ 26 if (!(obj)->unique_id().empty()) { \ 27 ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, (obj)->unique_id().c_str()); \ 29 if ((obj)->get_force_update()) { \ 30 ESP_LOGV(TAG, "%s Force Update: YES", prefix); \ 34 #define SUB_SENSOR(name) \ 36 sensor::Sensor *name##_sensor_{nullptr}; \ 39 void set_##name##_sensor(sensor::Sensor *sensor) { this->name##_sensor_ = sensor; } 95 void add_filters(
const std::vector<Filter *> &filters);
98 void set_filters(
const std::vector<Filter *> &filters);
bool get_force_update() const
Get whether force update mode is enabled.
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.
void set_force_update(bool force_update)
Set force update mode.
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.
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.
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.
bool force_update_
Force update mode.
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.
Base-class for all sensors.
esphome::sensor::Sensor * sensor