mirror of
https://github.com/esphome/esphome.git
synced 2025-07-28 14:16:40 +00:00
Fix BLE connection loop caused by timeout and pending disconnect race (#8597)
This commit is contained in:
parent
86033b6612
commit
aa6e172e14
@ -265,6 +265,12 @@ void BluetoothProxy::bluetooth_device_request(const api::BluetoothDeviceRequest
|
|||||||
connection->get_connection_index(), connection->address_str().c_str());
|
connection->get_connection_index(), connection->address_str().c_str());
|
||||||
return;
|
return;
|
||||||
} else if (connection->state() == espbt::ClientState::CONNECTING) {
|
} else if (connection->state() == espbt::ClientState::CONNECTING) {
|
||||||
|
if (connection->disconnect_pending()) {
|
||||||
|
ESP_LOGW(TAG, "[%d] [%s] Connection request while pending disconnect, cancelling pending disconnect",
|
||||||
|
connection->get_connection_index(), connection->address_str().c_str());
|
||||||
|
connection->cancel_pending_disconnect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
ESP_LOGW(TAG, "[%d] [%s] Connection request ignored, already connecting", connection->get_connection_index(),
|
ESP_LOGW(TAG, "[%d] [%s] Connection request ignored, already connecting", connection->get_connection_index(),
|
||||||
connection->address_str().c_str());
|
connection->address_str().c_str());
|
||||||
return;
|
return;
|
||||||
|
@ -173,6 +173,8 @@ class ESPBTClient : public ESPBTDeviceListener {
|
|||||||
virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) = 0;
|
virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) = 0;
|
||||||
virtual void connect() = 0;
|
virtual void connect() = 0;
|
||||||
virtual void disconnect() = 0;
|
virtual void disconnect() = 0;
|
||||||
|
bool disconnect_pending() const { return this->want_disconnect_; }
|
||||||
|
void cancel_pending_disconnect() { this->want_disconnect_ = false; }
|
||||||
virtual void set_state(ClientState st) {
|
virtual void set_state(ClientState st) {
|
||||||
this->state_ = st;
|
this->state_ = st;
|
||||||
if (st == ClientState::IDLE) {
|
if (st == ClientState::IDLE) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user