ESPHome 2025.12.0-dev
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 {
32namespace esp32_improv {
33
34using namespace esp32_ble_server;
35
37 public:
39 void dump_config() override;
40 void loop() override;
41 void setup() override;
43
44 float get_setup_priority() const override;
45 void start();
46 void stop();
47 bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
48
49#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
50 void add_on_state_callback(std::function<void(improv::State, improv::Error)> &&callback) {
51 this->state_callback_.add(std::move(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
73 uint32_t identify_start_{0};
75 uint32_t authorized_start_{0};
77
78 uint32_t wifi_timeout_{};
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 esp32_improv
127} // namespace esphome
128
129#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 add_on_state_callback(std::function< void(improv::State, improv::Error)> &&callback)
void set_state_(improv::State state, bool update_advertising=true)
const char * state_to_string_(improv::State state)
bool state
Definition fan.h:0
ESP32ImprovComponent * global_improv_component
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7