ESPHome 2026.10.2
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 final : public Trigger<StringRef, size_t> {
10 public:
11 explicit SelectStateTrigger(Select *parent) : parent_(parent) {
13 [this](size_t index) { this->trigger(StringRef(this->parent_->option_at(index)), index); });
14 }
15
16 protected:
18};
19
20template<size_t N, typename... Ts> class SelectIsCondition final : public Condition<Ts...> {
21 public:
22 SelectIsCondition(Select *parent, const char *const *option_list) : parent_(parent), option_list_(option_list) {}
23
24 bool check(const Ts &...x) override {
25 auto current = this->parent_->current_option();
26 for (size_t i = 0; i != N; i++) {
27 if (current == this->option_list_[i]) {
28 return true;
29 }
30 }
31 return false;
32 }
33
34 protected:
36 const char *const *option_list_;
37};
38
39template<typename... Ts> class SelectIsCondition<0, Ts...> final : public Condition<Ts...> {
40 public:
41 SelectIsCondition(Select *parent, std::function<bool(const StringRef &, const Ts &...)> &&f)
42 : parent_(parent), f_(f) {}
43
44 bool check(const Ts &...x) override { return this->f_(this->parent_->current_option(), x...); }
45
46 protected:
48 std::function<bool(const StringRef &, const Ts &...)> f_;
49};
50} // namespace esphome::select
Base class for all automation conditions.
Definition automation.h:505
StringRef is a reference to a string owned by something else.
Definition string_ref.h:30
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition automation.h:528
Base-class for all selects.
Definition select.h:29
void add_on_state_callback(F &&callback)
Definition select.h:74
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:60
StringRef current_option() const
Return the currently selected option, or empty StringRef if no state.
Definition select.h:43
SelectIsCondition(Select *parent, std::function< bool(const StringRef &, const Ts &...)> &&f)
Definition automation.h:41
bool check(const Ts &...x) override
Definition automation.h:44
std::function< bool(const StringRef &, const Ts &...)> f_
Definition automation.h:48
bool check(const Ts &...x) override
Definition automation.h:24
const char *const * option_list_
Definition automation.h:36
SelectIsCondition(Select *parent, const char *const *option_list)
Definition automation.h:22
uint16_t x
Definition tt21100.cpp:5