ESPHome 2026.5.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::ota {
8
9class OTAStateChangeTrigger final : public Trigger<OTAState>, public OTAStateListener {
10 public:
11 explicit OTAStateChangeTrigger(OTAComponent *parent) : parent_(parent) { parent->add_state_listener(this); }
12
13 void on_ota_state(OTAState state, float progress, uint8_t error) override {
14 if (!this->parent_->is_failed()) {
15 this->trigger(state);
16 }
17 }
18
19 protected:
21};
22
23template<OTAState State> class OTAStateTrigger final : public Trigger<>, public OTAStateListener {
24 public:
25 explicit OTAStateTrigger(OTAComponent *parent) : parent_(parent) { parent->add_state_listener(this); }
26
27 void on_ota_state(OTAState state, float progress, uint8_t error) override {
28 if (state == State && !this->parent_->is_failed()) {
29 this->trigger();
30 }
31 }
32
33 protected:
35};
36
40
41class OTAProgressTrigger final : public Trigger<float>, public OTAStateListener {
42 public:
43 explicit OTAProgressTrigger(OTAComponent *parent) : parent_(parent) { parent->add_state_listener(this); }
44
45 void on_ota_state(OTAState state, float progress, uint8_t error) override {
46 if (state == OTA_IN_PROGRESS && !this->parent_->is_failed()) {
47 this->trigger(progress);
48 }
49 }
50
51 protected:
53};
54
55class OTAErrorTrigger final : public Trigger<uint8_t>, public OTAStateListener {
56 public:
57 explicit OTAErrorTrigger(OTAComponent *parent) : parent_(parent) { parent->add_state_listener(this); }
58
59 void on_ota_state(OTAState state, float progress, uint8_t error) override {
60 if (state == OTA_ERROR && !this->parent_->is_failed()) {
61 this->trigger(error);
62 }
63 }
64
65 protected:
67};
68
69} // namespace esphome::ota
70#endif
bool is_failed() const
Definition component.h:284
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition automation.h:482
void add_state_listener(OTAStateListener *listener)
Definition ota_backend.h:66
OTAErrorTrigger(OTAComponent *parent)
Definition automation.h:57
void on_ota_state(OTAState state, float progress, uint8_t error) override
Definition automation.h:59
OTAProgressTrigger(OTAComponent *parent)
Definition automation.h:43
void on_ota_state(OTAState state, float progress, uint8_t error) override
Definition automation.h:45
OTAStateChangeTrigger(OTAComponent *parent)
Definition automation.h:11
void on_ota_state(OTAState state, float progress, uint8_t error) override
Definition automation.h:13
Listener interface for OTA state changes.
Definition ota_backend.h:57
OTAStateTrigger(OTAComponent *parent)
Definition automation.h:25
void on_ota_state(OTAState state, float progress, uint8_t error) override
Definition automation.h:27
bool state
Definition fan.h:2