ESPHome 2025.5.0
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
3#include "udp_component.h"
4#ifdef USE_NETWORK
6
7#include <vector>
8
9namespace esphome {
10namespace udp {
11
12template<typename... Ts> class UDPWriteAction : public Action<Ts...>, public Parented<UDPComponent> {
13 public:
14 void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) {
15 this->data_func_ = func;
16 this->static_ = false;
17 }
18 void set_data_static(const std::vector<uint8_t> &data) {
19 this->data_static_ = data;
20 this->static_ = true;
21 }
22
23 void play(Ts... x) override {
24 if (this->static_) {
25 this->parent_->send_packet(this->data_static_);
26 } else {
27 auto val = this->data_func_(x...);
28 this->parent_->send_packet(val);
29 }
30 }
31
32 protected:
33 bool static_{false};
34 std::function<std::vector<uint8_t>(Ts...)> data_func_{};
35 std::vector<uint8_t> data_static_{};
36};
37
38} // namespace udp
39} // namespace esphome
40#endif
Helper class to easily give an object a parent of type T.
Definition helpers.h:538
void set_data_template(std::function< std::vector< uint8_t >(Ts...)> func)
Definition automation.h:14
void play(Ts... x) override
Definition automation.h:23
void set_data_static(const std::vector< uint8_t > &data)
Definition automation.h:18
std::vector< uint8_t > data_static_
Definition automation.h:35
std::function< std::vector< uint8_t >(Ts...)> data_func_
Definition automation.h:34
mopeka_std_values val[4]
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5