ESPHome 2026.11.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
9template<size_t N, typename... Ts> class SelectIsCondition final : public Condition<Ts...> {
10 public:
11 SelectIsCondition(Select *parent, const char *const *option_list) : parent_(parent), option_list_(option_list) {}
12
13 bool check(const Ts &...x) override {
14 auto current = this->parent_->current_option();
15 for (size_t i = 0; i != N; i++) {
16 if (current == this->option_list_[i]) {
17 return true;
18 }
19 }
20 return false;
21 }
22
23 protected:
25 const char *const *option_list_;
26};
27
28template<typename... Ts> class SelectIsCondition<0, Ts...> final : public Condition<Ts...> {
29 public:
30 SelectIsCondition(Select *parent, std::function<bool(const StringRef &, const Ts &...)> &&f)
31 : parent_(parent), f_(f) {}
32
33 bool check(const Ts &...x) override { return this->f_(this->parent_->current_option(), x...); }
34
35 protected:
37 std::function<bool(const StringRef &, const Ts &...)> f_;
38};
39} // namespace esphome::select
Base class for all automation conditions.
Definition automation.h:533
StringRef is a reference to a string owned by something else.
Definition string_ref.h:31
Base-class for all selects.
Definition select.h:28
StringRef current_option() const
Return the currently selected option, or empty StringRef if no state.
Definition select.h:42
SelectIsCondition(Select *parent, std::function< bool(const StringRef &, const Ts &...)> &&f)
Definition automation.h:30
bool check(const Ts &...x) override
Definition automation.h:33
std::function< bool(const StringRef &, const Ts &...)> f_
Definition automation.h:37
bool check(const Ts &...x) override
Definition automation.h:13
const char *const * option_list_
Definition automation.h:25
SelectIsCondition(Select *parent, const char *const *option_list)
Definition automation.h:11
uint16_t x
Definition tt21100.cpp:5