ESPHome  2022.6.2
template_text_sensor.cpp
Go to the documentation of this file.
1 #include "template_text_sensor.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace template_ {
6 
7 static const char *const TAG = "template.text_sensor";
8 
10  if (this->f_.has_value()) {
11  auto val = (*this->f_)();
12  if (val.has_value()) {
13  this->publish_state(*val);
14  }
15  } else if (this->has_state()) {
16  this->publish_state(this->state);
17  }
18 }
20 void TemplateTextSensor::set_template(std::function<optional<std::string>()> &&f) { this->f_ = f; }
21 void TemplateTextSensor::dump_config() { LOG_TEXT_SENSOR("", "Template Sensor", this); }
22 
23 } // namespace template_
24 } // namespace esphome
optional< std::function< optional< std::string >)> > f_
void publish_state(const std::string &state)
Definition: text_sensor.cpp:12
void set_template(std::function< optional< std::string >()> &&f)
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:17
Definition: a4988.cpp:4
uint32_t val
Definition: datatypes.h:85