From 40e2960264f626c8203256f628cb78e790fe0047 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 30 Jul 2025 22:15:39 -1000 Subject: [PATCH] fixes --- esphome/components/api/api_connection.h | 7 +++++++ .../bluetooth_proxy/bluetooth_connection.cpp | 10 ++++------ .../components/bluetooth_proxy/bluetooth_connection.h | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 5b64adecb3..21688e601c 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -235,6 +235,13 @@ class APIConnection : public APIServerConnection { this->is_authenticated(); } uint8_t get_log_subscription_level() const { return this->flags_.log_subscription; } + + // Get client API version for feature detection + bool client_supports_api_version(uint16_t major, uint16_t minor) const { + return this->client_api_version_major_ > major || + (this->client_api_version_major_ == major && this->client_api_version_minor_ >= minor); + } + void on_fatal_error() override; #ifdef USE_API_PASSWORD void on_unauthenticated_access() override; diff --git a/esphome/components/bluetooth_proxy/bluetooth_connection.cpp b/esphome/components/bluetooth_proxy/bluetooth_connection.cpp index ca784ddc39..b7326e3a4a 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_connection.cpp +++ b/esphome/components/bluetooth_proxy/bluetooth_connection.cpp @@ -24,11 +24,9 @@ static void fill_128bit_uuid_array(std::array &out, esp_bt_uuid_t u ((uint64_t) uuid.uuid.uuid128[1] << 8) | ((uint64_t) uuid.uuid.uuid128[0]); } -static bool supports_efficient_uuids(api::APIConnection *api_conn) { - if (!api_conn) - return false; - return api_conn->get_client_api_version_major() > 1 || - (api_conn->get_client_api_version_major() == 1 && api_conn->get_client_api_version_minor() >= 12); +bool BluetoothConnection::supports_efficient_uuids_() const { + auto *api_conn = this->proxy_->get_api_connection(); + return api_conn && api_conn->client_supports_api_version(1, 12); } void BluetoothConnection::dump_config() { @@ -82,7 +80,7 @@ void BluetoothConnection::send_service_for_discovery_() { } // Check if client supports efficient UUIDs - bool use_efficient_uuids = supports_efficient_uuids(api_conn); + bool use_efficient_uuids = this->supports_efficient_uuids_(); // Prepare response for up to 3 services api::BluetoothGATTGetServicesResponse resp; diff --git a/esphome/components/bluetooth_proxy/bluetooth_connection.h b/esphome/components/bluetooth_proxy/bluetooth_connection.h index 3fed9d531f..622d257bf8 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_connection.h +++ b/esphome/components/bluetooth_proxy/bluetooth_connection.h @@ -27,6 +27,7 @@ class BluetoothConnection : public esp32_ble_client::BLEClientBase { protected: friend class BluetoothProxy; + bool supports_efficient_uuids_() const; void send_service_for_discovery_(); void reset_connection_(esp_err_t reason);