ESPHome 2025.5.0
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2#ifdef USE_OTA_STATE_CALLBACK
3#include "ota_backend.h"
4
6
7namespace esphome {
8namespace ota {
9
10class OTAStateChangeTrigger : public Trigger<OTAState> {
11 public:
13 parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
14 if (!parent->is_failed()) {
16 }
17 });
18 }
19};
20
21class OTAStartTrigger : public Trigger<> {
22 public:
23 explicit OTAStartTrigger(OTAComponent *parent) {
24 parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
25 if (state == OTA_STARTED && !parent->is_failed()) {
26 trigger();
27 }
28 });
29 }
30};
31
32class OTAProgressTrigger : public Trigger<float> {
33 public:
34 explicit OTAProgressTrigger(OTAComponent *parent) {
35 parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
36 if (state == OTA_IN_PROGRESS && !parent->is_failed()) {
37 trigger(progress);
38 }
39 });
40 }
41};
42
43class OTAEndTrigger : public Trigger<> {
44 public:
45 explicit OTAEndTrigger(OTAComponent *parent) {
46 parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
47 if (state == OTA_COMPLETED && !parent->is_failed()) {
48 trigger();
49 }
50 });
51 }
52};
53
54class OTAAbortTrigger : public Trigger<> {
55 public:
56 explicit OTAAbortTrigger(OTAComponent *parent) {
57 parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
58 if (state == OTA_ABORT && !parent->is_failed()) {
59 trigger();
60 }
61 });
62 }
63};
64
65class OTAErrorTrigger : public Trigger<uint8_t> {
66 public:
67 explicit OTAErrorTrigger(OTAComponent *parent) {
68 parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
69 if (state == OTA_ERROR && !parent->is_failed()) {
70 trigger(error);
71 }
72 });
73 }
74};
75
76} // namespace ota
77} // namespace esphome
78#endif
bool is_failed() const
OTAAbortTrigger(OTAComponent *parent)
Definition automation.h:56
void add_on_state_callback(std::function< void(ota::OTAState, float, uint8_t)> &&callback)
Definition ota_backend.h:65
OTAEndTrigger(OTAComponent *parent)
Definition automation.h:45
OTAErrorTrigger(OTAComponent *parent)
Definition automation.h:67
OTAProgressTrigger(OTAComponent *parent)
Definition automation.h:34
OTAStartTrigger(OTAComponent *parent)
Definition automation.h:23
OTAStateChangeTrigger(OTAComponent *parent)
Definition automation.h:12
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7