ESPHome  2024.10.2
copy_select.cpp
Go to the documentation of this file.
1 #include "copy_select.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace copy {
6 
7 static const char *const TAG = "copy.select";
8 
10  source_->add_on_state_callback([this](const std::string &value, size_t index) { this->publish_state(value); });
11 
13 
14  if (source_->has_state())
15  this->publish_state(source_->state);
16 }
17 
18 void CopySelect::dump_config() { LOG_SELECT("", "Copy Select", this); }
19 
20 void CopySelect::control(const std::string &value) {
21  auto call = source_->make_call();
22  call.set_option(value);
23  call.perform();
24 }
25 
26 } // namespace copy
27 } // namespace esphome
void dump_config() override
Definition: copy_select.cpp:18
void setup() override
Definition: copy_select.cpp:9
SelectTraits traits
Definition: select.h:34
void set_options(std::vector< std::string > options)
void control(const std::string &value) override
Definition: copy_select.cpp:20
std::vector< std::string > get_options() const
SelectCall make_call()
Instantiate a SelectCall object to modify this select component&#39;s state.
Definition: select.h:42
std::string state
Definition: select.h:33
void publish_state(const std::string &state)
Definition: select.cpp:9
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool has_state() const
Return whether this select component has gotten a full state yet.
Definition: select.h:39
void add_on_state_callback(std::function< void(std::string, size_t)> &&callback)
Definition: select.cpp:22
select::Select * source_
Definition: copy_select.h:19