diff --git a/esphome/components/esp32_ble_client/ble_client_base.cpp b/esphome/components/esp32_ble_client/ble_client_base.cpp index 9a8b0006bc..8ae1eb1bac 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.cpp +++ b/esphome/components/esp32_ble_client/ble_client_base.cpp @@ -45,11 +45,16 @@ 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. - elif (this->state_ == espbt::ClientState::READY_TO_CONNECT) { this->connect(); } - elif (this->state_ == espbt::ClientState::IDLE) { this->disable_loop(); } + 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) { + this->disable_loop(); + } } float BLEClientBase::get_setup_priority() const { return setup_priority::AFTER_BLUETOOTH; }