From 6be22a5ea9c9b03ee125e4d77aceb90a77154a1a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 3 Aug 2025 19:15:28 -1000 Subject: [PATCH] [esp32_ble_client] Connect immediately on READY_TO_CONNECT to reduce latency (#10051) --- esphome/components/esp32_ble_client/ble_client_base.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/esphome/components/esp32_ble_client/ble_client_base.cpp b/esphome/components/esp32_ble_client/ble_client_base.cpp index 031cb41e6d..2c13995f76 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.cpp +++ b/esphome/components/esp32_ble_client/ble_client_base.cpp @@ -45,8 +45,10 @@ void BLEClientBase::set_state(espbt::ClientState st) { ESPBTClient::set_state(st); if (st == espbt::ClientState::READY_TO_CONNECT) { - // Enable loop when we need to connect + // Enable loop for state processing this->enable_loop(); + // Connect immediately instead of waiting for next loop + this->connect(); } } @@ -63,11 +65,6 @@ void BLEClientBase::loop() { } this->set_state(espbt::ClientState::IDLE); } - // READY_TO_CONNECT means we have discovered the device - // and the scanner has been stopped by the tracker. - else if (this->state_ == espbt::ClientState::READY_TO_CONNECT) { - this->connect(); - } // If its idle, we can disable the loop as set_state // will enable it again when we need to connect. else if (this->state_ == espbt::ClientState::IDLE) {