ESPHome 2025.11.0b4
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 bool should_start() const { return this->should_start_; }
49
50#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
51 void add_on_state_callback(std::function<void(improv::State, improv::Error)> &&callback) {
52 this->state_callback_.add(std::move(callback));
53 }
54#endif
55#ifdef USE_BINARY_SENSOR
56 void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
57#endif
58#ifdef USE_OUTPUT
59 void set_status_indicator(output::BinaryOutput *status_indicator) { this->status_indicator_ = status_indicator; }
60#endif
61 void set_identify_duration(uint32_t identify_duration) { this->identify_duration_ = identify_duration; }
62 void set_authorized_duration(uint32_t authorized_duration) { this->authorized_duration_ = authorized_duration; }
63
64 void set_wifi_timeout(uint32_t wifi_timeout) { this->wifi_timeout_ = wifi_timeout; }
65 uint32_t get_wifi_timeout() const { return this->wifi_timeout_; }
66
67 improv::State get_improv_state() const { return this->state_; }
68 improv::Error get_improv_error_state() const { return this->error_state_; }
69
70 protected:
71 bool should_start_{false};
72 bool setup_complete_{false};
73
74 uint32_t identify_start_{0};
76 uint32_t authorized_start_{0};
78
79 uint32_t wifi_timeout_{};
80
81 std::vector<uint8_t> incoming_data_;
83
90
91#ifdef USE_BINARY_SENSOR
93#endif
94#ifdef USE_OUTPUT
96#endif
97
98 improv::State state_{improv::STATE_STOPPED};
99 improv::Error error_state_{improv::ERROR_NONE};
100#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
101 CallbackManager<void(improv::State, improv::Error)> state_callback_{};
102#endif
103
109
110 void set_state_(improv::State state, bool update_advertising = true);
111 void set_error_(improv::Error error);
112 improv::State get_initial_state_() const;
113 void send_response_(std::vector<uint8_t> &&response);
117 bool check_identify_();
119#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
120 const char *state_to_string_(improv::State state);
121#endif
122};
123
124// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
125extern ESP32ImprovComponent *global_improv_component;
126
127} // namespace esp32_improv
128} // namespace esphome
129
130#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