ESPHome  2024.11.1
copy_sensor.cpp
Go to the documentation of this file.
1 #include "copy_sensor.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace copy {
6 
7 static const char *const TAG = "copy.sensor";
8 
10  source_->add_on_state_callback([this](float value) { this->publish_state(value); });
11  if (source_->has_state())
12  this->publish_state(source_->state);
13 }
14 
15 void CopySensor::dump_config() { LOG_SENSOR("", "Copy Sensor", this); }
16 
17 } // namespace copy
18 } // 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
float state
This member variable stores the last state that has passed through all filters.
Definition: sensor.h:131
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
void dump_config() override
Definition: copy_sensor.cpp:15
sensor::Sensor * source_
Definition: copy_sensor.h:17
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 setup() override
Definition: copy_sensor.cpp:9