ESPHome  2022.6.2
resistance_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace resistance {
8 
12 };
13 
14 class ResistanceSensor : public Component, public sensor::Sensor {
15  public:
16  void set_sensor(Sensor *sensor) { sensor_ = sensor; }
17  void set_configuration(ResistanceConfiguration configuration) { configuration_ = configuration; }
18  void set_resistor(float resistor) { resistor_ = resistor; }
19  void set_reference_voltage(float reference_voltage) { reference_voltage_ = reference_voltage; }
20 
21  void setup() override {
22  this->sensor_->add_on_state_callback([this](float value) { this->process_(value); });
23  if (this->sensor_->has_state())
24  this->process_(this->sensor_->state);
25  }
26  void dump_config() override;
27  float get_setup_priority() const override { return setup_priority::DATA; }
28 
29  protected:
30  void process_(float value);
33  float resistor_;
35 };
36 
37 } // namespace resistance
38 } // 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:83
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:18
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:132
ResistanceConfiguration configuration_
Definition: a4988.cpp:4
bool has_state() const
Return whether this sensor has gotten a full state (that passed through all filters) yet...
Definition: sensor.cpp:128
void set_reference_voltage(float reference_voltage)
Base-class for all sensors.
Definition: sensor.h:47