ESPHome  2024.7.1
resistance_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace resistance {
9 
13 };
14 
16  public:
17  void set_sensor(Sensor *sensor) { sensor_ = sensor; }
18  void set_configuration(ResistanceConfiguration configuration) { configuration_ = configuration; }
19  void set_resistor(float resistor) { resistor_ = resistor; }
20  void set_reference_voltage(float reference_voltage) { reference_voltage_ = reference_voltage; }
21 
22  void setup() override {
23  this->sensor_->add_on_state_callback([this](float value) { this->process_(value); });
24  if (this->sensor_->has_state())
25  this->process_(this->sensor_->state);
26  }
27  void dump_config() override;
28  float get_setup_priority() const override { return setup_priority::DATA; }
29 
30  protected:
31  void process_(float value);
34  float resistor_;
36 };
37 
38 } // namespace resistance
39 } // namespace esphome
void add_on_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time a filtered value arrives.
Definition: sensor.cpp:52
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void set_configuration(ResistanceConfiguration configuration)
float get_setup_priority() const override
float state
This member variable stores the last state that has passed through all filters.
Definition: sensor.h:131
ResistanceConfiguration configuration_
Abstract interface to mark components that provide resistance values.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool has_state() const
Return whether this sensor has gotten a full state (that passed through all filters) yet...
Definition: sensor.cpp:97
void set_reference_voltage(float reference_voltage)
Base-class for all sensors.
Definition: sensor.h:57