ESPHome  2022.12.8
esp32_improv_component.h
Go to the documentation of this file.
1 #pragma once
2 
9 #include "esphome/core/helpers.h"
11 
12 #include <vector>
13 
14 #ifdef USE_ESP32
15 
16 #include <improv.h>
17 
18 namespace esphome {
19 namespace esp32_improv {
20 
21 using namespace esp32_ble_server;
22 
24  public:
26  void dump_config() override;
27  void loop() override;
28  void setup() override;
29  void setup_characteristics();
30  void on_client_disconnect() override;
31 
32  float get_setup_priority() const override;
33  void start() override;
34  void stop() override;
35  bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
36 
37  void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
38  void set_status_indicator(output::BinaryOutput *status_indicator) { this->status_indicator_ = status_indicator; }
39  void set_identify_duration(uint32_t identify_duration) { this->identify_duration_ = identify_duration; }
40  void set_authorized_duration(uint32_t authorized_duration) { this->authorized_duration_ = authorized_duration; }
41 
42  protected:
43  bool should_start_{false};
44  bool setup_complete_{false};
45 
46  uint32_t identify_start_{0};
48  uint32_t authorized_start_{0};
50 
51  std::vector<uint8_t> incoming_data_;
53 
54  std::shared_ptr<BLEService> service_;
60 
61  binary_sensor::BinarySensor *authorizer_{nullptr};
62  output::BinaryOutput *status_indicator_{nullptr};
63 
64  improv::State state_{improv::STATE_STOPPED};
65  improv::Error error_state_{improv::ERROR_NONE};
66 
67  void set_state_(improv::State state);
68  void set_error_(improv::Error error);
69  void send_response_(std::vector<uint8_t> &response);
70  void process_incoming_data_();
71  void on_wifi_connect_timeout_();
72  bool check_identify_();
73 };
74 
75 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
77 
78 } // namespace esp32_improv
79 } // namespace esphome
80 
81 #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)
Definition: a4988.cpp:4
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:28
bool state
Definition: fan.h:34