ESPHome  2024.12.2
automation.h
Go to the documentation of this file.
1 #pragma once
2 #ifdef USE_ESP32
3 #ifdef USE_ESP32_IMPROV_STATE_CALLBACK
5 
7 
8 #include <improv.h>
9 
10 namespace esphome {
11 namespace esp32_improv {
12 
14  public:
16  parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
17  if (state == improv::STATE_PROVISIONED && !parent->is_failed()) {
18  trigger();
19  }
20  });
21  }
22 };
23 
25  public:
27  parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
28  if (state == improv::STATE_PROVISIONING && !parent->is_failed()) {
29  trigger();
30  }
31  });
32  }
33 };
34 
35 class ESP32ImprovStartTrigger : public Trigger<> {
36  public:
38  parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
39  if ((state == improv::STATE_AUTHORIZED || state == improv::STATE_AWAITING_AUTHORIZATION) &&
40  !parent->is_failed()) {
41  trigger();
42  }
43  });
44  }
45 };
46 
47 class ESP32ImprovStateTrigger : public Trigger<improv::State, improv::Error> {
48  public:
50  parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
51  if (!parent->is_failed()) {
52  trigger(state, error);
53  }
54  });
55  }
56 };
57 
59  public:
61  parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
62  if (state == improv::STATE_STOPPED && !parent->is_failed()) {
63  trigger();
64  }
65  });
66  }
67 };
68 
69 } // namespace esp32_improv
70 } // namespace esphome
71 #endif
72 #endif
bool is_failed() const
Definition: component.cpp:143
ESP32ImprovProvisionedTrigger(ESP32ImprovComponent *parent)
Definition: automation.h:15
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
void add_on_state_callback(std::function< void(improv::State, improv::Error)> &&callback)
ESP32ImprovStartTrigger(ESP32ImprovComponent *parent)
Definition: automation.h:37
ESP32ImprovStoppedTrigger(ESP32ImprovComponent *parent)
Definition: automation.h:60
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
ESP32ImprovStateTrigger(ESP32ImprovComponent *parent)
Definition: automation.h:49
bool state
Definition: fan.h:34
ESP32ImprovProvisioningTrigger(ESP32ImprovComponent *parent)
Definition: automation.h:26