From 1dba01e05b92b8274acf4da78aae532a14037803 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 23 Feb 2026 09:48:23 -0600 Subject: [PATCH] [esp32_ble_client] Don't reset conn_id_ in want_disconnect_ path The CLOSE_EVT handler matches on conn_id_ to call set_idle_(). Resetting conn_id_ to UNSET_CONN_ID before CLOSE_EVT arrives causes the event to be dropped, leaving the client stuck in DISCONNECTING state permanently. Co-Authored-By: Claude Opus 4.6 --- esphome/components/esp32_ble_client/ble_client_base.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/esp32_ble_client/ble_client_base.cpp b/esphome/components/esp32_ble_client/ble_client_base.cpp index 906113aec3..72b3ebaa5a 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.cpp +++ b/esphome/components/esp32_ble_client/ble_client_base.cpp @@ -318,8 +318,8 @@ bool BLEClientBase::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ // Disconnect was requested after connecting started, // but before the connection was established. Now that we have // this->conn_id_ set, we can disconnect it. + // Don't reset conn_id_ here — CLOSE_EVT needs it to match and call set_idle_(). this->unconditional_disconnect(); - this->conn_id_ = UNSET_CONN_ID; break; } // MTU negotiation already started in ESP_GATTC_CONNECT_EVT