ESPHome  2024.9.2
esp32_improv_component.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
5 #include "esphome/core/helpers.h"
7 
11 
12 #ifdef USE_BINARY_SENSOR
14 #endif
15 
16 #ifdef USE_OUTPUT
18 #endif
19 
20 #include <vector>
21 
22 #ifdef USE_ESP32
23 
24 #include <improv.h>
25 
26 namespace esphome {
27 namespace esp32_improv {
28 
29 using namespace esp32_ble_server;
30 
32  public:
34  void dump_config() override;
35  void loop() override;
36  void setup() override;
37  void setup_characteristics();
38  void on_client_disconnect() override;
39 
40  float get_setup_priority() const override;
41  void start() override;
42  void stop() override;
43  bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
44 
45 #ifdef USE_BINARY_SENSOR
46  void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
47 #endif
48 #ifdef USE_OUTPUT
49  void set_status_indicator(output::BinaryOutput *status_indicator) { this->status_indicator_ = status_indicator; }
50 #endif
51  void set_identify_duration(uint32_t identify_duration) { this->identify_duration_ = identify_duration; }
52  void set_authorized_duration(uint32_t authorized_duration) { this->authorized_duration_ = authorized_duration; }
53 
54  void set_wifi_timeout(uint32_t wifi_timeout) { this->wifi_timeout_ = wifi_timeout; }
55  uint32_t get_wifi_timeout() const { return this->wifi_timeout_; }
56 
57  protected:
58  bool should_start_{false};
59  bool setup_complete_{false};
60 
61  uint32_t identify_start_{0};
63  uint32_t authorized_start_{0};
65 
66  uint32_t wifi_timeout_{};
67 
68  std::vector<uint8_t> incoming_data_;
70 
71  BLEService *service_ = nullptr;
77 
78 #ifdef USE_BINARY_SENSOR
79  binary_sensor::BinarySensor *authorizer_{nullptr};
80 #endif
81 #ifdef USE_OUTPUT
82  output::BinaryOutput *status_indicator_{nullptr};
83 #endif
84 
86  improv::Error error_state_{improv::ERROR_NONE};
87 
88  bool status_indicator_state_{false};
89  void set_status_indicator_state_(bool state);
90 
91  void set_state_(improv::State state);
92  void set_error_(improv::Error error);
93  void send_response_(std::vector<uint8_t> &response);
94  void process_incoming_data_();
95  void on_wifi_connect_timeout_();
96  bool check_identify_();
97 };
98 
99 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
101 
102 } // namespace esp32_improv
103 } // namespace esphome
104 
105 #endif
void setup()
void loop()
void set_authorized_duration(uint32_t authorized_duration)
void set_identify_duration(uint32_t identify_duration)
void set_authorizer(binary_sensor::BinarySensor *authorizer)
ESP32ImprovComponent * global_improv_component
void set_status_indicator(output::BinaryOutput *status_indicator)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:37
bool state
Definition: fan.h:34