Maurice Makaay 44b68f140e
Select enhancement (#3423)
Co-authored-by: Maurice Makaay <mmakaay1@xs4all.net>
2022-05-10 16:41:16 +12:00

28 lines
663 B
C++

#include "copy_select.h"
#include "esphome/core/log.h"
namespace esphome {
namespace copy {
static const char *const TAG = "copy.select";
void CopySelect::setup() {
source_->add_on_state_callback([this](const std::string &value, size_t index) { this->publish_state(value); });
traits.set_options(source_->traits.get_options());
if (source_->has_state())
this->publish_state(source_->state);
}
void CopySelect::dump_config() { LOG_SELECT("", "Copy Select", this); }
void CopySelect::control(const std::string &value) {
auto call = source_->make_call();
call.set_option(value);
call.perform();
}
} // namespace copy
} // namespace esphome