ESPHome 2025.12.5
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
5#include "select.h"
6
7namespace esphome::select {
8
9class SelectStateTrigger : public Trigger<std::string, size_t> {
10 public:
11 explicit SelectStateTrigger(Select *parent) {
12 parent->add_on_state_callback([this](const std::string &value, size_t index) { this->trigger(value, index); });
13 }
14};
15
16template<typename... Ts> class SelectSetAction : public Action<Ts...> {
17 public:
18 explicit SelectSetAction(Select *select) : select_(select) {}
19 TEMPLATABLE_VALUE(std::string, option)
20
21 void play(const Ts &...x) override {
22 auto call = this->select_->make_call();
23 call.set_option(this->option_.value(x...));
24 call.perform();
25 }
26
27 protected:
29};
30
31template<typename... Ts> class SelectSetIndexAction : public Action<Ts...> {
32 public:
33 explicit SelectSetIndexAction(Select *select) : select_(select) {}
34 TEMPLATABLE_VALUE(size_t, index)
35
36 void play(const Ts &...x) override {
37 auto call = this->select_->make_call();
38 call.set_index(this->index_.value(x...));
39 call.perform();
40 }
41
42 protected:
44};
45
46template<typename... Ts> class SelectOperationAction : public Action<Ts...> {
47 public:
48 explicit SelectOperationAction(Select *select) : select_(select) {}
49 TEMPLATABLE_VALUE(bool, cycle)
51
52 void play(const Ts &...x) override {
53 auto call = this->select_->make_call();
54 call.with_operation(this->operation_.value(x...));
55 if (this->cycle_.has_value()) {
56 call.with_cycle(this->cycle_.value(x...));
57 }
58 call.perform();
59 }
60
61 protected:
63};
64
65} // namespace esphome::select
virtual void play(const Ts &...x)=0
SelectCall & with_operation(SelectOperation operation)
SelectCall & set_index(size_t index)
SelectCall & set_option(const char *option, size_t len)
Base-class for all selects.
Definition select.h:30
void add_on_state_callback(std::function< void(std::string, size_t)> &&callback)
Definition select.cpp:44
SelectCall make_call()
Instantiate a SelectCall object to modify this select component's state.
Definition select.h:52
TEMPLATABLE_VALUE(bool, cycle) TEMPLATABLE_VALUE(SelectOperation
operation void play(const Ts &...x) override
Definition automation.h:52
TEMPLATABLE_VALUE(std::string, option) void play(const Ts &...x) override
Definition automation.h:19
TEMPLATABLE_VALUE(size_t, index) void play(const Ts &...x) override
Definition automation.h:34
uint16_t x
Definition tt21100.cpp:5