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