[esp32_ble_tracker] Quiet the teardown of a scan that is still starting

stop_scan_() logs an error for STARTING, which the settle right after it
makes moot; only ask the controller to stop a scan that is running. Fold the
two adjacent client-count guards and fix the services_released_ comment.
This commit is contained in:
J. Nick Koston
2026-09-10 09:34:08 -05:00
parent 2a9d11f14b
commit decbeb6a80
2 changed files with 6 additions and 5 deletions
@@ -140,7 +140,7 @@ class BLEClientBase : public espbt::ESPBTClient, public Component {
uint8_t pending_notify_regs_{0};
bool auto_connect_{false};
bool paired_{false};
// Set only when release_services() cleans the stack's GATT cache, which no API may then walk
// Always set by release_services(); the stack's GATT database must not be walked after it
bool services_released_{false};
// 8 bytes used, no padding
@@ -219,17 +219,18 @@ void ESP32BLETracker::stop_scan() {
}
void ESP32BLETracker::ble_before_disabled_event_handler() {
this->stop_scan_();
// Tell the controller to stop; a scan still starting has nothing to stop yet.
if (this->scanner_state_ == ScannerState::RUNNING || this->scanner_state_ == ScannerState::FAILED) {
this->stop_scan_();
}
#ifdef ESPHOME_ESP32_BLE_TRACKER_CLIENT_COUNT
for (auto *client : this->clients_) {
client->ble_before_disabled_event_handler();
}
this->skip_next_scan_end_ = false;
#endif
// The stop above never completes (stack torn down, events dropped); settle
// here so start_scan_() sees IDLE once the stack is back.
#ifdef ESPHOME_ESP32_BLE_TRACKER_CLIENT_COUNT
this->skip_next_scan_end_ = false;
#endif
if (this->scanner_state_ != ScannerState::IDLE) {
this->cleanup_scan_state_(true);
}