mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 23:48:11 +01:00
fix add and delete actions
This commit is contained in:
parent
ff4469f828
commit
ea814e3c63
4 changed files with 48 additions and 12 deletions
|
@ -278,7 +278,7 @@ async def send_action(config, action_id, template_arg, args):
|
|||
key=CONF_PEER,
|
||||
),
|
||||
)
|
||||
async def del_peer_action(config, action_id, template_arg, args):
|
||||
async def add_del_peer_action(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
template_ = await cg.templatable(config[CONF_PEER], args, cg.uint64)
|
||||
cg.add(var.set_peer(template_))
|
||||
|
|
|
@ -316,26 +316,20 @@ template<typename... Ts> class SendAction : public Action<Ts...>, public Parente
|
|||
|
||||
template<typename... Ts> class NewPeerAction : public Action<Ts...>, public Parented<ESPNowComponent> {
|
||||
public:
|
||||
template<typename V> void set_peer(V peer) { this->peer_ = peer; }
|
||||
TEMPLATABLE_VALUE(uint64_t, peer);
|
||||
void play(Ts... x) override {
|
||||
auto peer = this->peer_.value(x...);
|
||||
parent_->add_peer(peer);
|
||||
}
|
||||
|
||||
protected:
|
||||
TemplatableValue<uint64_t, Ts...> mac_{};
|
||||
};
|
||||
|
||||
template<typename... Ts> class DelPeerAction : public Action<Ts...>, public Parented<ESPNowComponent> {
|
||||
public:
|
||||
template<typename V> void set_peer(V peer) { this->peer_ = peer; }
|
||||
TEMPLATABLE_VALUE(uint64_t, peer);
|
||||
void play(Ts... x) override {
|
||||
auto peer = this->peer_.value(x...);
|
||||
parent_->del_peer(peer);
|
||||
}
|
||||
|
||||
protected:
|
||||
TemplatableValue<uint64_t, Ts...> peer_{};
|
||||
};
|
||||
|
||||
class ESPNowSentTrigger : public Trigger<const ESPNowPacket, bool> {
|
||||
|
|
|
@ -7,6 +7,7 @@ esp32:
|
|||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf
|
||||
# version: 5.1.5
|
||||
|
||||
esphome:
|
||||
name: "${name}"
|
||||
|
@ -56,3 +57,12 @@ interval:
|
|||
- espnow.broatcast:
|
||||
payload: "hallo everyone"
|
||||
command: 123
|
||||
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin: GPIO39
|
||||
name: Button
|
||||
on_click:
|
||||
- espnow.peer.new:
|
||||
peer: kGf7Ii0t
|
||||
- espnow.peer.del: kGf7Ii0t
|
||||
|
|
|
@ -7,14 +7,46 @@ espnow:
|
|||
auto_add_peer: true
|
||||
peers:
|
||||
- FF:FF:FF:FF:FF:FF
|
||||
- 0xFFFFFFFFFFFF
|
||||
- ZZZZZZZZ
|
||||
on_receive:
|
||||
- logger.log:
|
||||
format: "Received: %s RSSI: %d"
|
||||
args: [packet.get_payload(), packet.rssi]
|
||||
format: "Received: '%s' from '%s' command: %d RSSI: %d"
|
||||
args:
|
||||
[
|
||||
packet.get_payload(),
|
||||
packet.get_peer_code().c_str(),
|
||||
packet.get_command(),
|
||||
packet.rssi,
|
||||
]
|
||||
|
||||
on_broadcast:
|
||||
- command: 123
|
||||
then:
|
||||
- logger.log:
|
||||
format: "Broadcast Received from: '%s' RSSI: %d: %s"
|
||||
args:
|
||||
[
|
||||
packet.get_peer_code().c_str(),
|
||||
packet.rssi,
|
||||
packet.get_payload(),
|
||||
]
|
||||
|
||||
interval:
|
||||
- interval: 10sec
|
||||
then:
|
||||
- espnow.broatcast:
|
||||
payload: "hallo everyone"
|
||||
command: 123
|
||||
- espnow.send:
|
||||
payload: "hallo everyone"
|
||||
command: 123
|
||||
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin: GPIO39
|
||||
name: Button
|
||||
on_click:
|
||||
- espnow.send: "hallo everyone"
|
||||
- espnow.peer.new:
|
||||
peer: kGf7Ii0t
|
||||
- espnow.peer.del: kGf7Ii0t
|
||||
|
|
Loading…
Reference in a new issue