ESPHome 2025.5.0
Loading...
Searching...
No Matches
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
5namespace esphome {
6namespace template_ {
7
8static 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}
20void 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
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:39
float get_setup_priority() const override
optional< std::function< optional< float >()> > f_
void set_template(std::function< optional< float >()> &&f)
mopeka_std_values val[4]
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:18
const char *const TAG
Definition spi.cpp:8
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7