ESPHome 2026.5.0
Loading...
Searching...
No Matches
esp32_improv_component.h
Go to the documentation of this file.
1#pragma once
2
7
12
13#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
15#endif
16
17#ifdef USE_BINARY_SENSOR
19#endif
20
21#ifdef USE_OUTPUT
23#endif
24
25#include <vector>
26
27#ifdef USE_ESP32
28
29#include <improv.h>
30
31namespace esphome::esp32_improv {
32
33using namespace esp32_ble_server;
34
36 public:
38 void dump_config() override;
39 void loop() override;
40 void setup() override;
42
43 float get_setup_priority() const override;
44 void start();
45 void stop();
46 bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
47 bool should_start() const { return this->should_start_; }
48
49#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
50 template<typename F> void add_on_state_callback(F &&callback) {
51 this->state_callback_.add(std::forward<F>(callback));
52 }
53#endif
54#ifdef USE_BINARY_SENSOR
55 void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
56#endif
57#ifdef USE_OUTPUT
58 void set_status_indicator(output::BinaryOutput *status_indicator) { this->status_indicator_ = status_indicator; }
59#endif
60 void set_identify_duration(uint32_t identify_duration) { this->identify_duration_ = identify_duration; }
61 void set_authorized_duration(uint32_t authorized_duration) { this->authorized_duration_ = authorized_duration; }
62
63 void set_wifi_timeout(uint32_t wifi_timeout) { this->wifi_timeout_ = wifi_timeout; }
64 uint32_t get_wifi_timeout() const { return this->wifi_timeout_; }
65
66 improv::State get_improv_state() const { return this->state_; }
67 improv::Error get_improv_error_state() const { return this->error_state_; }
68
69 protected:
70 bool should_start_{false};
71 bool setup_complete_{false};
72
77
79
80 std::vector<uint8_t> incoming_data_;
82
89
90#ifdef USE_BINARY_SENSOR
92#endif
93#ifdef USE_OUTPUT
95#endif
96
97 improv::State state_{improv::STATE_STOPPED};
98 improv::Error error_state_{improv::ERROR_NONE};
99#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
100 CallbackManager<void(improv::State, improv::Error)> state_callback_{};
101#endif
102
108
109 void set_state_(improv::State state, bool update_advertising = true);
110 void set_error_(improv::Error error);
111 improv::State get_initial_state_() const;
112 void send_response_(std::vector<uint8_t> &&response);
116 bool check_identify_();
118#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
119 const char *state_to_string_(improv::State state);
120#endif
121};
122
123// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
124extern ESP32ImprovComponent *global_improv_component;
125
126} // namespace esphome::esp32_improv
127
128#endif
Base class for all binary_sensor-type classes.
void set_authorized_duration(uint32_t authorized_duration)
void set_identify_duration(uint32_t identify_duration)
void send_response_(std::vector< uint8_t > &&response)
void set_status_indicator(output::BinaryOutput *status_indicator)
void set_authorizer(binary_sensor::BinarySensor *authorizer)
CallbackManager< void(improv::State, improv::Error)> state_callback_
void set_state_(improv::State state, bool update_advertising=true)
const char * state_to_string_(improv::State state)
bool state
Definition fan.h:2
ESP32ImprovComponent * global_improv_component
static void uint32_t