mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 09:01:49 +00:00 
			
		
		
		
	[esp32_ble_tracker] Simplify BLE client state machine by removing READY_TO_CONNECT
This commit is contained in:
		@@ -58,8 +58,8 @@ void BLEClientBase::loop() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    this->set_state(espbt::ClientState::IDLE);
 | 
					    this->set_state(espbt::ClientState::IDLE);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  // If its idle, we can disable the loop as set_state
 | 
					  // If idle, we can disable the loop as connect()
 | 
				
			||||||
  // will enable it again when we need to connect.
 | 
					  // will enable it again when a connection is needed.
 | 
				
			||||||
  else if (this->state_ == espbt::ClientState::IDLE) {
 | 
					  else if (this->state_ == espbt::ClientState::IDLE) {
 | 
				
			||||||
    this->disable_loop();
 | 
					    this->disable_loop();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -101,6 +101,13 @@ bool BLEClientBase::parse_device(const espbt::ESPBTDevice &device) {
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BLEClientBase::connect() {
 | 
					void BLEClientBase::connect() {
 | 
				
			||||||
 | 
					  // Prevent duplicate connection attempts
 | 
				
			||||||
 | 
					  if (this->state_ == espbt::ClientState::CONNECTING || this->state_ == espbt::ClientState::CONNECTED ||
 | 
				
			||||||
 | 
					      this->state_ == espbt::ClientState::ESTABLISHED) {
 | 
				
			||||||
 | 
					    ESP_LOGW(TAG, "[%d] [%s] Connection already in progress, state=%s", this->connection_index_,
 | 
				
			||||||
 | 
					             this->address_str_.c_str(), espbt::client_state_to_string(this->state_));
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  ESP_LOGI(TAG, "[%d] [%s] 0x%02x Connecting", this->connection_index_, this->address_str_.c_str(),
 | 
					  ESP_LOGI(TAG, "[%d] [%s] 0x%02x Connecting", this->connection_index_, this->address_str_.c_str(),
 | 
				
			||||||
           this->remote_addr_type_);
 | 
					           this->remote_addr_type_);
 | 
				
			||||||
  this->paired_ = false;
 | 
					  this->paired_ = false;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user