ESPHome  2024.11.0
template_sensor.cpp
Go to the documentation of this file.
1 #include "template_sensor.h"
2 #include "esphome/core/log.h"
3 #include <cmath>
4 
5 namespace esphome {
6 namespace template_ {
7 
8 static const char *const TAG = "template.sensor";
9 
11  if (!this->f_.has_value())
12  return;
13 
14  auto val = (*this->f_)();
15  if (val.has_value()) {
16  this->publish_state(*val);
17  }
18 }
20 void TemplateSensor::set_template(std::function<optional<float>()> &&f) { this->f_ = f; }
22  LOG_SENSOR("", "Template Sensor", this);
23  LOG_UPDATE_INTERVAL(this);
24 }
25 
26 } // namespace template_
27 } // namespace esphome
float get_setup_priority() const override
void set_template(std::function< optional< float >()> &&f)
mopeka_std_values val[4]
const char *const TAG
Definition: spi.cpp:8
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
optional< std::function< optional< float >)> > f_