#pragma once #include "uart.h" #include "esphome/core/automation.h" namespace esphome { namespace uart { template class UARTWriteAction : public Action, public Parented { public: void set_data_template(std::function(Ts...)> func) { this->data_func_ = func; this->static_ = false; } void set_data_static(const std::vector &data) { this->data_static_ = data; this->static_ = true; } void play(Ts... x) override { if (this->static_) { this->parent_->write_array(this->data_static_); } else { auto val = this->data_func_(x...); this->parent_->write_array(val); } } protected: bool static_{false}; std::function(Ts...)> data_func_{}; std::vector data_static_{}; }; } // namespace uart } // namespace esphome