mirror of
https://github.com/esphome/esphome.git
synced 2025-09-27 07:32:22 +01:00
Fixes for BLE/improv (#1878)
This commit is contained in:
@@ -27,7 +27,7 @@ void ESP32ImprovComponent::setup_service() {
|
||||
|
||||
this->rpc_ =
|
||||
this->service_->create_characteristic(improv::RPC_COMMAND_UUID, esp32_ble::BLECharacteristic::PROPERTY_WRITE);
|
||||
this->rpc_->on_write([this](std::vector<uint8_t> &data) {
|
||||
this->rpc_->on_write([this](const std::vector<uint8_t> &data) {
|
||||
if (data.size() > 0) {
|
||||
this->incoming_data_.insert(this->incoming_data_.end(), data.begin(), data.end());
|
||||
}
|
||||
@@ -123,13 +123,17 @@ void ESP32ImprovComponent::loop() {
|
||||
std::string url = "https://my.home-assistant.io/redirect/config_flow_start?domain=esphome";
|
||||
std::vector<uint8_t> data = improv::build_rpc_response(improv::WIFI_SETTINGS, {url});
|
||||
this->send_response(data);
|
||||
this->set_timeout("end-service", 1000, [this] {
|
||||
this->service_->stop();
|
||||
this->set_state_(improv::STATE_STOPPED);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case improv::STATE_PROVISIONED: {
|
||||
this->incoming_data_.clear();
|
||||
if (this->status_indicator_ != nullptr)
|
||||
this->status_indicator_->turn_on();
|
||||
this->status_indicator_->turn_off();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -188,8 +192,10 @@ void ESP32ImprovComponent::start() {
|
||||
}
|
||||
|
||||
void ESP32ImprovComponent::end() {
|
||||
this->set_state_(improv::STATE_STOPPED);
|
||||
this->service_->stop();
|
||||
this->set_timeout("end-service", 1000, [this] {
|
||||
this->service_->stop();
|
||||
this->set_state_(improv::STATE_STOPPED);
|
||||
});
|
||||
}
|
||||
|
||||
float ESP32ImprovComponent::get_setup_priority() const {
|
||||
|
@@ -26,7 +26,7 @@ class ESP32ImprovComponent : public Component, public esp32_ble::BLEServiceCompo
|
||||
float get_setup_priority() const override;
|
||||
void start();
|
||||
void end();
|
||||
bool is_active() const { return this->state_ == improv::STATE_AUTHORIZED; }
|
||||
bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
|
||||
|
||||
void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
|
||||
void set_status_indicator(output::BinaryOutput *status_indicator) { this->status_indicator_ = status_indicator; }
|
||||
|
Reference in New Issue
Block a user