ESPHome 2026.1.0-dev
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) : parent_(parent) {
13 [this](size_t index) { this->trigger(std::string(this->parent_->option_at(index)), index); });
14 }
15
16 protected:
18};
19
20template<typename... Ts> class SelectSetAction : public Action<Ts...> {
21 public:
22 explicit SelectSetAction(Select *select) : select_(select) {}
23 TEMPLATABLE_VALUE(std::string, option)
24
25 void play(const Ts &...x) override {
26 auto call = this->select_->make_call();
27 call.set_option(this->option_.value(x...));
28 call.perform();
29 }
30
31 protected:
33};
34
35template<typename... Ts> class SelectSetIndexAction : public Action<Ts...> {
36 public:
37 explicit SelectSetIndexAction(Select *select) : select_(select) {}
38 TEMPLATABLE_VALUE(size_t, index)
39
40 void play(const Ts &...x) override {
41 auto call = this->select_->make_call();
42 call.set_index(this->index_.value(x...));
43 call.perform();
44 }
45
46 protected:
48};
49
50template<typename... Ts> class SelectOperationAction : public Action<Ts...> {
51 public:
52 explicit SelectOperationAction(Select *select) : select_(select) {}
53 TEMPLATABLE_VALUE(bool, cycle)
55
56 void play(const Ts &...x) override {
57 auto call = this->select_->make_call();
58 call.with_operation(this->operation_.value(x...));
59 if (this->cycle_.has_value()) {
60 call.with_cycle(this->cycle_.value(x...));
61 }
62 call.perform();
63 }
64
65 protected:
67};
68
69} // 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
const char * option_at(size_t index) const
Return the option value at the provided index offset (as const char* from flash).
Definition select.cpp:83
SelectCall make_call()
Instantiate a SelectCall object to modify this select component's state.
Definition select.h:52
void add_on_state_callback(std::function< void(size_t)> &&callback)
Definition select.cpp:43
TEMPLATABLE_VALUE(bool, cycle) TEMPLATABLE_VALUE(SelectOperation
operation void play(const Ts &...x) override
Definition automation.h:56
TEMPLATABLE_VALUE(std::string, option) void play(const Ts &...x) override
Definition automation.h:23
TEMPLATABLE_VALUE(size_t, index) void play(const Ts &...x) override
Definition automation.h:38
uint16_t x
Definition tt21100.cpp:5