ESPHome  2024.3.2
automation.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "select.h"
6 
7 namespace esphome {
8 namespace select {
9 
10 class SelectStateTrigger : public Trigger<std::string, size_t> {
11  public:
12  explicit SelectStateTrigger(Select *parent) {
13  parent->add_on_state_callback([this](const std::string &value, size_t index) { this->trigger(value, index); });
14  }
15 };
16 
17 template<typename... Ts> class SelectSetAction : public Action<Ts...> {
18  public:
19  explicit SelectSetAction(Select *select) : select_(select) {}
20  TEMPLATABLE_VALUE(std::string, option)
21 
22  void play(Ts... x) override {
23  auto call = this->select_->make_call();
24  call.set_option(this->option_.value(x...));
25  call.perform();
26  }
27 
28  protected:
30 };
31 
32 template<typename... Ts> class SelectSetIndexAction : public Action<Ts...> {
33  public:
34  explicit SelectSetIndexAction(Select *select) : select_(select) {}
35  TEMPLATABLE_VALUE(size_t, index)
36 
37  void play(Ts... x) override {
38  auto call = this->select_->make_call();
39  call.set_index(this->index_.value(x...));
40  call.perform();
41  }
42 
43  protected:
45 };
46 
47 template<typename... Ts> class SelectOperationAction : public Action<Ts...> {
48  public:
49  explicit SelectOperationAction(Select *select) : select_(select) {}
50  TEMPLATABLE_VALUE(bool, cycle)
51  TEMPLATABLE_VALUE(SelectOperation, operation)
52 
53  void play(Ts... x) override {
54  auto call = this->select_->make_call();
55  call.with_operation(this->operation_.value(x...));
56  if (this->cycle_.has_value()) {
57  call.with_cycle(this->cycle_.value(x...));
58  }
59  call.perform();
60  }
61 
62  protected:
64 };
65 
66 } // namespace select
67 } // namespace esphome
TEMPLATABLE_VALUE(std::string, option) void play(Ts... x) override
Definition: automation.h:20
uint16_t x
Definition: tt21100.cpp:17
SelectSetAction(Select *select)
Definition: automation.h:19
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
TEMPLATABLE_VALUE(size_t, index) void play(Ts... x) override
Definition: automation.h:35
Base-class for all selects.
Definition: select.h:31
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void add_on_state_callback(std::function< void(std::string, size_t)> &&callback)
Definition: select.cpp:22