[esp32_ble] Honour an enable made during the disable callbacks

The before-disabled callbacks can run user automations (on_scan_end fires
when the tracker settles the scanner), so an enable issued there was flipped
to ACTIVE and then overwritten by the DISABLED write after the teardown.
Turn it into a bring-up instead. ble_client also skips advertisements until
its app is registered, so the tracker does not stop the scan for a connect
that would be rejected.
This commit is contained in:
J. Nick Koston
2026-09-10 08:50:34 -05:00
parent 7f4de6c5bd
commit 2a9d11f14b
2 changed files with 8 additions and 1 deletions
+4 -1
View File
@@ -586,7 +586,10 @@ void ESP32BLE::loop_handle_state_transition_not_active_() {
return;
}
this->drain_ble_events_();
this->state_ = BLE_COMPONENT_STATE_DISABLED;
// A status callback may have asked for BLE back; the stack is down now, so
// that request becomes a bring-up.
this->state_ =
this->state_ == BLE_COMPONENT_STATE_ACTIVE ? BLE_COMPONENT_STATE_ENABLE : BLE_COMPONENT_STATE_DISABLED;
} else if (this->state_ == BLE_COMPONENT_STATE_ENABLE) {
ESP_LOGD(TAG, "Enabling");
this->state_ = BLE_COMPONENT_STATE_OFF;
@@ -108,6 +108,10 @@ bool BLEClientBase::parse_device(const espbt::ESPBTDevice &device) {
return false;
if (this->state() != espbt::ClientState::IDLE)
return false;
// Not registered on this stack yet; promoting now would stop the scan for a
// connect that connect() rejects anyway.
if (this->gattc_if_ == ESP_GATT_IF_NONE)
return false;
this->log_event_("Found device");
if (ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG)