From 7d314398e15f19bb19a7516a98abceb80789cdf0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 17 Jun 2025 22:27:24 +0200 Subject: [PATCH] cleaner fix --- .../components/esp32_ble_client/ble_client_base.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/esphome/components/esp32_ble_client/ble_client_base.cpp b/esphome/components/esp32_ble_client/ble_client_base.cpp index ef1d427113..9a8b0006bc 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.cpp +++ b/esphome/components/esp32_ble_client/ble_client_base.cpp @@ -26,11 +26,8 @@ void BLEClientBase::set_state(espbt::ClientState st) { ESP_LOGV(TAG, "[%d] [%s] Set state %d", this->connection_index_, this->address_str_.c_str(), (int) st); ESPBTClient::set_state(st); - // Disable loop when idle AND address is not set (unused connection slot) - if (st == espbt::ClientState::IDLE && this->address_ == 0) { - this->disable_loop(); - } else if (st == espbt::ClientState::READY_TO_CONNECT || st == espbt::ClientState::INIT) { - // Enable loop when we need to initialize or connect + if (st == espbt::ClientState::READY_TO_CONNECT) { + // Enable loop when we need to connect this->enable_loop(); } } @@ -51,9 +48,8 @@ void BLEClientBase::loop() { // READY_TO_CONNECT means we have discovered the device // and the scanner has been stopped by the tracker. - if (this->state_ == espbt::ClientState::READY_TO_CONNECT) { - this->connect(); - } + elif (this->state_ == espbt::ClientState::READY_TO_CONNECT) { this->connect(); } + elif (this->state_ == espbt::ClientState::IDLE) { this->disable_loop(); } } float BLEClientBase::get_setup_priority() const { return setup_priority::AFTER_BLUETOOTH; }