diff --git a/esphome/components/esp32_ble/ble.cpp b/esphome/components/esp32_ble/ble.cpp index 387a16263c..085cfbba1c 100644 --- a/esphome/components/esp32_ble/ble.cpp +++ b/esphome/components/esp32_ble/ble.cpp @@ -580,12 +580,7 @@ void ESP32BLE::loop_handle_state_transition_not_active_() { this->mark_failed(); return; } - // Drop what the old stack queued; the next stack reuses the same interface ids. - BLEEvent *ble_event; - while ((ble_event = this->ble_events_.pop()) != nullptr) { - this->ble_event_pool_.release(ble_event); - } - this->ble_events_.get_and_reset_dropped_count(); + this->drain_ble_events_(); this->state_ = BLE_COMPONENT_STATE_DISABLED; } else if (this->state_ == BLE_COMPONENT_STATE_ENABLE) { ESP_LOGD(TAG, "Enabling"); diff --git a/esphome/components/esp32_ble/ble.h b/esphome/components/esp32_ble/ble.h index 7d2d0438a4..35bf4b5b9f 100644 --- a/esphome/components/esp32_ble/ble.h +++ b/esphome/components/esp32_ble/ble.h @@ -176,6 +176,14 @@ class ESP32BLE final : public Component { bool ble_setup_(); bool ble_dismantle_(); + // Drop what the old stack queued; the next stack reuses the same interface ids. + void drain_ble_events_() { + BLEEvent *ble_event; + while ((ble_event = this->ble_events_.pop()) != nullptr) { + this->ble_event_pool_.release(ble_event); + } + this->ble_events_.get_and_reset_dropped_count(); + } bool ble_pre_setup_(); #ifdef USE_ESP32_BLE_ADVERTISING void advertising_init_();