ESPHome 2025.5.0
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
5#include "select.h"
6
7namespace esphome {
8namespace select {
9
10class 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
17template<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
32template<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
47template<typename... Ts> class SelectOperationAction : public Action<Ts...> {
48 public:
49 explicit SelectOperationAction(Select *select) : select_(select) {}
50 TEMPLATABLE_VALUE(bool, cycle)
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
virtual void play(Ts... x)=0
SelectCall & with_operation(SelectOperation operation)
SelectCall & set_index(size_t index)
SelectCall & set_option(const std::string &option)
Base-class for all selects.
Definition select.h:31
void add_on_state_callback(std::function< void(std::string, size_t)> &&callback)
Definition select.cpp:22
SelectCall make_call()
Instantiate a SelectCall object to modify this select component's state.
Definition select.h:42
TEMPLATABLE_VALUE(bool, cycle) TEMPLATABLE_VALUE(SelectOperation
operation void play(Ts... x) override
Definition automation.h:53
TEMPLATABLE_VALUE(std::string, option) void play(Ts... x) override
Definition automation.h:20
TEMPLATABLE_VALUE(size_t, index) void play(Ts... x) override
Definition automation.h:35
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5