ESPHome 2026.3.0
Loading...
Searching...
No Matches
copy_select.cpp
Go to the documentation of this file.
1#include "copy_select.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace copy {
6
7static const char *const TAG = "copy.select";
8
10 source_->add_on_state_callback([this](size_t index) { this->publish_state(index); });
11
13
14 auto idx = this->source_->active_index();
15 if (idx.has_value())
16 this->publish_state(*idx);
17}
18
19void CopySelect::dump_config() { LOG_SELECT("", "Copy Select", this); }
20
21void CopySelect::control(size_t index) {
22 auto call = source_->make_call();
23 call.set_index(index);
24 call.perform();
25}
26
27} // namespace copy
28} // namespace esphome
void control(size_t index) override
select::Select * source_
Definition copy_select.h:18
void dump_config() override
SelectCall & set_index(size_t index)
SelectCall make_call()
Instantiate a SelectCall object to modify this select component's state.
Definition select.h:53
optional< size_t > active_index() const
Return the (optional) index offset of the currently active option.
Definition select.cpp:70
void add_on_state_callback(std::function< void(size_t)> &&callback)
Definition select.cpp:45
SelectTraits traits
Definition select.h:31
void publish_state(const std::string &state)
Definition select.cpp:11
const FixedVector< const char * > & get_options() const
void set_options(const std::initializer_list< const char * > &options)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7