ESPHome  2024.4.1
automation.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/defines.h"
4 #ifdef USE_OTA_STATE_CALLBACK
5 
9 
10 namespace esphome {
11 namespace ota {
12 
13 class OTAStateChangeTrigger : public Trigger<OTAState> {
14  public:
15  explicit OTAStateChangeTrigger(OTAComponent *parent) {
16  parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
17  if (!parent->is_failed()) {
18  return trigger(state);
19  }
20  });
21  }
22 };
23 
24 class OTAStartTrigger : public Trigger<> {
25  public:
26  explicit OTAStartTrigger(OTAComponent *parent) {
27  parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
28  if (state == OTA_STARTED && !parent->is_failed()) {
29  trigger();
30  }
31  });
32  }
33 };
34 
35 class OTAProgressTrigger : public Trigger<float> {
36  public:
37  explicit OTAProgressTrigger(OTAComponent *parent) {
38  parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
39  if (state == OTA_IN_PROGRESS && !parent->is_failed()) {
40  trigger(progress);
41  }
42  });
43  }
44 };
45 
46 class OTAEndTrigger : public Trigger<> {
47  public:
48  explicit OTAEndTrigger(OTAComponent *parent) {
49  parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
50  if (state == OTA_COMPLETED && !parent->is_failed()) {
51  trigger();
52  }
53  });
54  }
55 };
56 
57 class OTAErrorTrigger : public Trigger<uint8_t> {
58  public:
59  explicit OTAErrorTrigger(OTAComponent *parent) {
60  parent->add_on_state_callback([this, parent](OTAState state, float progress, uint8_t error) {
61  if (state == OTA_ERROR && !parent->is_failed()) {
62  trigger(error);
63  }
64  });
65  }
66 };
67 
68 } // namespace ota
69 } // namespace esphome
70 
71 #endif // USE_OTA_STATE_CALLBACK
void add_on_state_callback(std::function< void(OTAState, float, uint8_t)> &&callback)
OTAProgressTrigger(OTAComponent *parent)
Definition: automation.h:37
OTAStartTrigger(OTAComponent *parent)
Definition: automation.h:26
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
OTAErrorTrigger(OTAComponent *parent)
Definition: automation.h:59
OTAEndTrigger(OTAComponent *parent)
Definition: automation.h:48
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
OTAStateChangeTrigger(OTAComponent *parent)
Definition: automation.h:15
OTAComponent provides a simple way to integrate Over-the-Air updates into your app using ArduinoOTA...
Definition: ota_component.h:44
bool state
Definition: fan.h:34