From 85abff84c64f7b6658c1a7296421608f91aeb130 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 18 Nov 2025 01:08:37 +0000 Subject: [PATCH] [bthome] Fix compilation errors and enhance StaticVector - Add StaticVector::clear() method for resetting container - Add StaticVector::push_back(T&&) for move semantics support (unique_ptr) - Use esp_bt_dev_get_address() instead of esp_read_mac for BLE MAC - Include esp_bt_device.h for Bluetooth device functions Fixes compilation errors with StaticVector clear() and unique_ptr push_back, and uses correct API for retrieving Bluetooth MAC address. --- esphome/components/bthome/bthome.cpp | 6 +++--- esphome/core/helpers.h | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/esphome/components/bthome/bthome.cpp b/esphome/components/bthome/bthome.cpp index 378af93c7b..7270cf9733 100644 --- a/esphome/components/bthome/bthome.cpp +++ b/esphome/components/bthome/bthome.cpp @@ -6,6 +6,7 @@ #ifndef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID #include #endif +#include #include #include #include @@ -460,9 +461,8 @@ bool BTHome::encrypt_payload_(const uint8_t *plaintext, size_t plaintext_len, ui return false; } - // Get MAC address - uint8_t mac[6]; - esp_read_mac(mac, ESP_MAC_BT); + // Get Bluetooth MAC address + const uint8_t *mac = esp_bt_dev_get_address(); // Build nonce according to BTHome spec: // MAC (6 bytes) + UUID (2 bytes) + device info (1 byte) + counter (4 bytes) = 13 bytes diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 16eab8b8f6..7a1a9a2901 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -149,6 +149,13 @@ template class StaticVector { } } + // Move version for types like unique_ptr + void push_back(T &&value) { + if (count_ < N) { + data_[count_++] = std::move(value); + } + } + // Return reference to next element and increment count (with bounds checking) T &emplace_next() { if (count_ >= N) { @@ -159,6 +166,8 @@ template class StaticVector { return data_[count_++]; } + void clear() { count_ = 0; } + size_t size() const { return count_; } bool empty() const { return count_ == 0; }