From 7afb2fe077692109f2b4f59c78d397dee6130a09 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 18 Jul 2025 14:43:05 -1000 Subject: [PATCH] preen --- .../bluetooth_proxy/bluetooth_connection.cpp | 14 +++++++------- .../bluetooth_proxy/bluetooth_connection.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/esphome/components/bluetooth_proxy/bluetooth_connection.cpp b/esphome/components/bluetooth_proxy/bluetooth_connection.cpp index ea41396c5c..82ec88cde7 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_connection.cpp +++ b/esphome/components/bluetooth_proxy/bluetooth_connection.cpp @@ -42,7 +42,10 @@ void BluetoothConnection::loop() { this->send_service_for_discovery_(); } -void BluetoothConnection::reset_connection_() { +void BluetoothConnection::reset_connection_(esp_err_t reason) { + // Send disconnection notification + this->proxy_->send_device_connection(this->address_, false, 0, reason); + // Important: If we were in the middle of sending services, we do NOT send // send_gatt_services_done() here. This ensures the client knows that // the service discovery was interrupted and can retry. The client @@ -191,19 +194,16 @@ bool BluetoothConnection::gattc_event_handler(esp_gattc_cb_event_t event, esp_ga switch (event) { case ESP_GATTC_DISCONNECT_EVT: { - this->proxy_->send_device_connection(this->address_, false, 0, param->disconnect.reason); - this->reset_connection_(); + this->reset_connection_(param->disconnect.reason); break; } case ESP_GATTC_CLOSE_EVT: { - this->proxy_->send_device_connection(this->address_, false, 0, param->close.reason); - this->reset_connection_(); + this->reset_connection_(param->close.reason); break; } case ESP_GATTC_OPEN_EVT: { if (param->open.status != ESP_GATT_OK && param->open.status != ESP_GATT_ALREADY_OPEN) { - this->proxy_->send_device_connection(this->address_, false, 0, param->open.status); - this->reset_connection_(); + this->reset_connection_(param->open.status); } else if (this->connection_type_ == espbt::ConnectionType::V3_WITH_CACHE) { this->proxy_->send_device_connection(this->address_, true, this->mtu_); this->proxy_->send_connections_free(); diff --git a/esphome/components/bluetooth_proxy/bluetooth_connection.h b/esphome/components/bluetooth_proxy/bluetooth_connection.h index 4c4eff0919..2673238fba 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_connection.h +++ b/esphome/components/bluetooth_proxy/bluetooth_connection.h @@ -29,7 +29,7 @@ class BluetoothConnection : public esp32_ble_client::BLEClientBase { friend class BluetoothProxy; void send_service_for_discovery_(); - void reset_connection_(); + void reset_connection_(esp_err_t reason); // Memory optimized layout for 32-bit systems // Group 1: Pointers (4 bytes each, naturally aligned)