ESPHome  2024.11.1
template_binary_sensor.cpp
Go to the documentation of this file.
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace template_ {
6 
7 static const char *const TAG = "template.binary_sensor";
8 
10  if (!this->publish_initial_state_)
11  return;
12 
13  if (this->f_ != nullptr) {
14  this->publish_initial_state(this->f_().value_or(false));
15  } else {
16  this->publish_initial_state(false);
17  }
18 }
20  if (this->f_ == nullptr)
21  return;
22 
23  auto s = this->f_();
24  if (s.has_value()) {
25  this->publish_state(*s);
26  }
27 }
28 void TemplateBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Template Binary Sensor", this); }
29 
30 } // namespace template_
31 } // namespace esphome
void publish_initial_state(bool state)
Publish the initial state, this will not make the callback manager send callbacks and is meant only f...
std::function< optional< bool >)> f_
const char *const TAG
Definition: spi.cpp:8
void publish_state(bool state)
Publish a new state to the front-end.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7