Fixes for actions

This commit is contained in:
2025-03-03 09:46:15 +01:00
parent 7bc36b2a90
commit 176304db46
3 changed files with 49 additions and 25 deletions

View File

@@ -1,8 +1,36 @@
#include "automation.h"
#include "esphome/core/log.h"
#pragma once
#include "uart.h"
#include "esphome/core/automation.h"
#include <vector>
namespace esphome {
static const char *const TAG = "switch.automation";
template<typename... Ts> class Marlin2WriteAction : public Action<Ts...>, public Parented<UARTComponent> {
public:
void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) {
this->data_func_ = func;
this->static_ = false;
}
void set_data_static(const std::vector<uint8_t> &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<std::vector<uint8_t>(Ts...)> data_func_{};
std::vector<uint8_t> data_static_{};
};
} // namespace esphome