3#if defined(USE_ESP32) || defined(USE_ESP8266)
13 TEMPLATABLE_VALUE(peer_address_t,
address);
14 TEMPLATABLE_BYTES(data)
17 void add_on_sent(
const std::initializer_list<
Action<Ts...> *> &actions) {
19 if (this->
flags_.wait_for_sent) {
23 void add_on_error(
const std::initializer_list<
Action<Ts...> *> &actions) {
25 if (this->
flags_.wait_for_sent) {
27 if (this->flags_.continue_on_error) {
28 this->play_next_(x...);
36 void set_wait_for_sent(
bool wait_for_sent) { this->flags_.wait_for_sent = wait_for_sent; }
37 void set_continue_on_error(
bool continue_on_error) { this->flags_.continue_on_error = continue_on_error; }
39 void play_complex(
const Ts &...
x)
override {
42 if (status == ESP_OK) {
43 if (!this->sent_.empty()) {
44 this->sent_.play(
x...);
45 }
else if (this->flags_.wait_for_sent) {
46 this->play_next_(
x...);
49 if (!this->error_.empty()) {
50 this->error_.play(
x...);
51 }
else if (this->flags_.wait_for_sent) {
52 if (this->flags_.continue_on_error) {
53 this->play_next_(
x...);
60 peer_address_t
address = this->address_.value(
x...);
63 [&](
const uint8_t *data,
size_t len) { err = this->parent_->send(
address.data(), data,
len, send_callback); },
67 }
else if (!this->flags_.wait_for_sent) {
68 this->play_next_(
x...);
73 void play(
const Ts &...
x)
override { }
91 public ESPNowReceivedPacketHandler {
94 memcpy(this->address_,
address.data(), ESP_NOW_ETH_ALEN);
100 bool match = !this->has_address_ || (memcmp(this->address_, info.
src_addr, ESP_NOW_ETH_ALEN) == 0);
104 this->trigger(info, data, size);
109 bool has_address_{
false};
110 uint8_t address_[ESP_NOW_ETH_ALEN]{};
113 public ESPNowUnknownPeerHandler {
116 this->trigger(info, data, size);
121 public ESPNowBroadcastHandler {
124 memcpy(this->address_,
address.data(), ESP_NOW_ETH_ALEN);
129 bool match = !this->has_address_ || (memcmp(this->address_, info.
src_addr, ESP_NOW_ETH_ALEN) == 0);
133 this->trigger(info, data, size);
138 bool has_address_{
false};
139 uint8_t address_[ESP_NOW_ETH_ALEN]{};
void add_action(Action< Ts... > *action)
void add_actions(const std::initializer_list< Action< Ts... > * > &actions)
Helper class to easily give an object a parent of type T.
bool on_broadcast(const ESPNowRecvInfo &info, const uint8_t *data, uint16_t size) override
OnBroadcastTrigger(std::array< uint8_t, ESP_NOW_ETH_ALEN > address)
bool on_receive(const ESPNowRecvInfo &info, const uint8_t *data, uint16_t size) override
OnReceiveTrigger(std::array< uint8_t, ESP_NOW_ETH_ALEN > address)
bool on_unknown_peer(const ESPNowRecvInfo &info, const uint8_t *data, uint16_t size) override
ActionList< Ts... > sent_
void play(const Ts &...x) override
uint8_t continue_on_error
struct esphome::espnow::SendAction::@87 flags_
ActionList< Ts... > error_
std::function< void(esp_err_t)> send_callback_t
uint8_t src_addr[ESP_NOW_ETH_ALEN]
Source address of ESPNOW packet.