ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2#ifdef USE_OTA_STATE_LISTENER
3#include "ota_backend.h"
4
6
7namespace esphome {
8namespace ota {
9
10class OTAStateChangeTrigger final : public Trigger<OTAState>, public OTAStateListener {
11 public:
12 explicit OTAStateChangeTrigger(OTAComponent *parent) : parent_(parent) { parent->add_state_listener(this); }
13
14 void on_ota_state(OTAState state, float progress, uint8_t error) override {
15 if (!this->parent_->is_failed()) {
16 this->trigger(state);
17 }
18 }
19
20 protected:
22};
23
24template<OTAState State> class OTAStateTrigger final : public Trigger<>, public OTAStateListener {
25 public:
26 explicit OTAStateTrigger(OTAComponent *parent) : parent_(parent) { parent->add_state_listener(this); }
27
28 void on_ota_state(OTAState state, float progress, uint8_t error) override {
29 if (state == State && !this->parent_->is_failed()) {
30 this->trigger();
31 }
32 }
33
34 protected:
36};
37
41
42class OTAProgressTrigger final : public Trigger<float>, public OTAStateListener {
43 public:
44 explicit OTAProgressTrigger(OTAComponent *parent) : parent_(parent) { parent->add_state_listener(this); }
45
46 void on_ota_state(OTAState state, float progress, uint8_t error) override {
47 if (state == OTA_IN_PROGRESS && !this->parent_->is_failed()) {
48 this->trigger(progress);
49 }
50 }
51
52 protected:
54};
55
56class OTAErrorTrigger final : public Trigger<uint8_t>, public OTAStateListener {
57 public:
58 explicit OTAErrorTrigger(OTAComponent *parent) : parent_(parent) { parent->add_state_listener(this); }
59
60 void on_ota_state(OTAState state, float progress, uint8_t error) override {
61 if (state == OTA_ERROR && !this->parent_->is_failed()) {
62 this->trigger(error);
63 }
64 }
65
66 protected:
68};
69
70} // namespace ota
71} // namespace esphome
72#endif
bool is_failed() const
void trigger(const Ts &...x)
Definition automation.h:204
void add_state_listener(OTAStateListener *listener)
Definition ota_backend.h:77
OTAErrorTrigger(OTAComponent *parent)
Definition automation.h:58
void on_ota_state(OTAState state, float progress, uint8_t error) override
Definition automation.h:60
OTAProgressTrigger(OTAComponent *parent)
Definition automation.h:44
void on_ota_state(OTAState state, float progress, uint8_t error) override
Definition automation.h:46
OTAStateChangeTrigger(OTAComponent *parent)
Definition automation.h:12
void on_ota_state(OTAState state, float progress, uint8_t error) override
Definition automation.h:14
Listener interface for OTA state changes.
Definition ota_backend.h:68
OTAStateTrigger(OTAComponent *parent)
Definition automation.h:26
void on_ota_state(OTAState state, float progress, uint8_t error) override
Definition automation.h:28
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7