ESPHome  2024.12.2
automation.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <utility>
4 
8 
9 namespace esphome {
10 namespace text_sensor {
11 
12 class TextSensorStateTrigger : public Trigger<std::string> {
13  public:
14  explicit TextSensorStateTrigger(TextSensor *parent) {
15  parent->add_on_state_callback([this](const std::string &value) { this->trigger(value); });
16  }
17 };
18 
19 class TextSensorStateRawTrigger : public Trigger<std::string> {
20  public:
22  parent->add_on_raw_state_callback([this](const std::string &value) { this->trigger(value); });
23  }
24 };
25 
26 template<typename... Ts> class TextSensorStateCondition : public Condition<Ts...> {
27  public:
28  explicit TextSensorStateCondition(TextSensor *parent) : parent_(parent) {}
29 
30  TEMPLATABLE_VALUE(std::string, state)
31 
32  bool check(Ts... x) override { return this->parent_->state == this->state_.value(x...); }
33 
34  protected:
36 };
37 
38 template<typename... Ts> class TextSensorPublishAction : public Action<Ts...> {
39  public:
40  TextSensorPublishAction(TextSensor *sensor) : sensor_(sensor) {}
41  TEMPLATABLE_VALUE(std::string, state)
42 
43  void play(Ts... x) override { this->sensor_->publish_state(this->state_.value(x...)); }
44 
45  protected:
47 };
48 
49 } // namespace text_sensor
50 } // namespace esphome
void add_on_state_callback(std::function< void(std::string)> callback)
Definition: text_sensor.cpp:52
uint16_t x
Definition: tt21100.cpp:17
TEMPLATABLE_VALUE(std::string, state) bool check(Ts... x) override
Definition: automation.h:30
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
void add_on_raw_state_callback(std::function< void(std::string)> callback)
Add a callback that will be called every time the sensor sends a raw value.
Definition: text_sensor.cpp:55
Base class for all automation conditions.
Definition: automation.h:74
TEMPLATABLE_VALUE(std::string, state) void play(Ts... x) override
Definition: automation.h:41
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
esphome::sensor::Sensor * sensor
Definition: statsd.h:38
bool state
Definition: fan.h:34