#pragma once #include "esphome/core/automation.h" #include "esphome/core/component.h" #include "select.h" namespace esphome { namespace select { class SelectStateTrigger : public Trigger { public: explicit SelectStateTrigger(Select *parent) { parent->add_on_state_callback([this](const std::string &value, size_t index) { this->trigger(value, index); }); } }; template class SelectSetAction : public Action { public: explicit SelectSetAction(Select *select) : select_(select) {} TEMPLATABLE_VALUE(std::string, option) void play(Ts... x) override { auto call = this->select_->make_call(); call.set_option(this->option_.value(x...)); call.perform(); } protected: Select *select_; }; template class SelectSetIndexAction : public Action { public: explicit SelectSetIndexAction(Select *select) : select_(select) {} TEMPLATABLE_VALUE(size_t, index) void play(Ts... x) override { auto call = this->select_->make_call(); call.set_index(this->index_.value(x...)); call.perform(); } protected: Select *select_; }; template class SelectOperationAction : public Action { public: explicit SelectOperationAction(Select *select) : select_(select) {} TEMPLATABLE_VALUE(bool, cycle) TEMPLATABLE_VALUE(SelectOperation, operation) void play(Ts... x) override { auto call = this->select_->make_call(); call.with_operation(this->operation_.value(x...)); if (this->cycle_.has_value()) { call.with_cycle(this->cycle_.value(x...)); } call.perform(); } protected: Select *select_; }; } // namespace select } // namespace esphome