mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-19 20:53:26 +02:00
8e75980ebd
* Cleanup dashboard JS * Add vscode * Save start_mark/end_mark * Updates * Updates * Remove need for cv.nameable It's a bit hacky but removes so much bloat from integrations * Add enum helper * Document APIs, and Improvements * Fixes * Fixes * Update PULL_REQUEST_TEMPLATE.md * Updates * Updates * Updates
27 lines
650 B
C++
27 lines
650 B
C++
#include "template_sensor.h"
|
|
#include "esphome/core/log.h"
|
|
|
|
namespace esphome {
|
|
namespace template_ {
|
|
|
|
static const char *TAG = "template.sensor";
|
|
|
|
void TemplateSensor::update() {
|
|
if (!this->f_.has_value())
|
|
return;
|
|
|
|
auto val = (*this->f_)();
|
|
if (val.has_value()) {
|
|
this->publish_state(*val);
|
|
}
|
|
}
|
|
float TemplateSensor::get_setup_priority() const { return setup_priority::HARDWARE; }
|
|
void TemplateSensor::set_template(std::function<optional<float>()> &&f) { this->f_ = f; }
|
|
void TemplateSensor::dump_config() {
|
|
LOG_SENSOR("", "Template Sensor", this);
|
|
LOG_UPDATE_INTERVAL(this);
|
|
}
|
|
|
|
} // namespace template_
|
|
} // namespace esphome
|