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; }