mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	[esp32_ble_tracker] Remove duplicate client promotion logic (#10321)
This commit is contained in:
		| @@ -307,14 +307,7 @@ void ESP32BLETracker::gap_scan_event_handler(const BLEScanResult &scan_result) { | |||||||
|  |  | ||||||
|   if (scan_result.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) { |   if (scan_result.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) { | ||||||
|     // Process the scan result immediately |     // Process the scan result immediately | ||||||
|     bool found_discovered_client = this->process_scan_result_(scan_result); |     this->process_scan_result_(scan_result); | ||||||
|  |  | ||||||
|     // If we found a discovered client that needs promotion, stop scanning |  | ||||||
|     // This replaces the promote_to_connecting logic from loop() |  | ||||||
|     if (found_discovered_client && this->scanner_state_ == ScannerState::RUNNING) { |  | ||||||
|       ESP_LOGD(TAG, "Found discovered client, stopping scan for connection"); |  | ||||||
|       this->stop_scan_(); |  | ||||||
|     } |  | ||||||
|   } else if (scan_result.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) { |   } else if (scan_result.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) { | ||||||
|     // Scan finished on its own |     // Scan finished on its own | ||||||
|     if (this->scanner_state_ != ScannerState::RUNNING) { |     if (this->scanner_state_ != ScannerState::RUNNING) { | ||||||
| @@ -720,20 +713,9 @@ bool ESPBTDevice::resolve_irk(const uint8_t *irk) const { | |||||||
|          ecb_ciphertext[13] == ((addr64 >> 16) & 0xff); |          ecb_ciphertext[13] == ((addr64 >> 16) & 0xff); | ||||||
| } | } | ||||||
|  |  | ||||||
| bool ESP32BLETracker::has_connecting_clients_() const { |  | ||||||
|   for (auto *client : this->clients_) { |  | ||||||
|     auto state = client->state(); |  | ||||||
|     if (state == ClientState::CONNECTING || state == ClientState::READY_TO_CONNECT) { |  | ||||||
|       return true; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|   return false; |  | ||||||
| } |  | ||||||
| #endif  // USE_ESP32_BLE_DEVICE | #endif  // USE_ESP32_BLE_DEVICE | ||||||
|  |  | ||||||
| bool ESP32BLETracker::process_scan_result_(const BLEScanResult &scan_result) { | void ESP32BLETracker::process_scan_result_(const BLEScanResult &scan_result) { | ||||||
|   bool found_discovered_client = false; |  | ||||||
|  |  | ||||||
|   // Process raw advertisements |   // Process raw advertisements | ||||||
|   if (this->raw_advertisements_) { |   if (this->raw_advertisements_) { | ||||||
|     for (auto *listener : this->listeners_) { |     for (auto *listener : this->listeners_) { | ||||||
| @@ -759,14 +741,6 @@ bool ESP32BLETracker::process_scan_result_(const BLEScanResult &scan_result) { | |||||||
|     for (auto *client : this->clients_) { |     for (auto *client : this->clients_) { | ||||||
|       if (client->parse_device(device)) { |       if (client->parse_device(device)) { | ||||||
|         found = true; |         found = true; | ||||||
|         // Check if this client is discovered and needs promotion |  | ||||||
|         if (client->state() == ClientState::DISCOVERED) { |  | ||||||
|           // Only check for connecting clients if we found a discovered client |  | ||||||
|           // This matches the original logic: !connecting && client->state() == DISCOVERED |  | ||||||
|           if (!this->has_connecting_clients_()) { |  | ||||||
|             found_discovered_client = true; |  | ||||||
|           } |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -775,8 +749,6 @@ bool ESP32BLETracker::process_scan_result_(const BLEScanResult &scan_result) { | |||||||
|     } |     } | ||||||
| #endif  // USE_ESP32_BLE_DEVICE | #endif  // USE_ESP32_BLE_DEVICE | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   return found_discovered_client; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void ESP32BLETracker::cleanup_scan_state_(bool is_stop_complete) { | void ESP32BLETracker::cleanup_scan_state_(bool is_stop_complete) { | ||||||
|   | |||||||
| @@ -292,12 +292,7 @@ class ESP32BLETracker : public Component, | |||||||
|   /// Common cleanup logic when transitioning scanner to IDLE state |   /// Common cleanup logic when transitioning scanner to IDLE state | ||||||
|   void cleanup_scan_state_(bool is_stop_complete); |   void cleanup_scan_state_(bool is_stop_complete); | ||||||
|   /// Process a single scan result immediately |   /// Process a single scan result immediately | ||||||
|   /// Returns true if a discovered client needs promotion to READY_TO_CONNECT |   void process_scan_result_(const BLEScanResult &scan_result); | ||||||
|   bool process_scan_result_(const BLEScanResult &scan_result); |  | ||||||
| #ifdef USE_ESP32_BLE_DEVICE |  | ||||||
|   /// Check if any clients are in connecting or ready to connect state |  | ||||||
|   bool has_connecting_clients_() const; |  | ||||||
| #endif |  | ||||||
|   /// Handle scanner failure states |   /// Handle scanner failure states | ||||||
|   void handle_scanner_failure_(); |   void handle_scanner_failure_(); | ||||||
|   /// Try to promote discovered clients to ready to connect |   /// Try to promote discovered clients to ready to connect | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user