diff --git a/esphome/components/esp32_ble_client/ble_client_base.cpp b/esphome/components/esp32_ble_client/ble_client_base.cpp index 8821c70ca3..115d785eae 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.cpp +++ b/esphome/components/esp32_ble_client/ble_client_base.cpp @@ -23,12 +23,6 @@ void BLEClientBase::setup() { } void BLEClientBase::loop() { - // If address is 0, this connection is not in use - if (this->address_ == 0) { - this->disable_loop(); - return; - } - if (!esp32_ble::global_ble->is_active()) { this->set_state(espbt::ClientState::INIT); return; @@ -41,6 +35,13 @@ void BLEClientBase::loop() { } this->set_state(espbt::ClientState::IDLE); } + + // If address is 0, this connection is not in use + if (this->address_ == 0) { + this->disable_loop(); + return; + } + // 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) { diff --git a/esphome/components/esp32_ble_client/ble_client_base.h b/esphome/components/esp32_ble_client/ble_client_base.h index 576c1cf526..69c7c31ad8 100644 --- a/esphome/components/esp32_ble_client/ble_client_base.h +++ b/esphome/components/esp32_ble_client/ble_client_base.h @@ -62,7 +62,9 @@ class BLEClientBase : public espbt::ESPBTClient, public Component { (uint8_t) (this->address_ >> 32) & 0xff, (uint8_t) (this->address_ >> 24) & 0xff, (uint8_t) (this->address_ >> 16) & 0xff, (uint8_t) (this->address_ >> 8) & 0xff, (uint8_t) (this->address_ >> 0) & 0xff); - // Re-enable loop() when a new address is assigned + } + // Re-enable loop() when a non-zero address is assigned + if (address != 0) { this->enable_loop(); } }