diff --git a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp index 6bd7af2eeb..723466a5ff 100644 --- a/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +++ b/esphome/components/bluetooth_proxy/bluetooth_proxy.cpp @@ -71,18 +71,14 @@ bool BluetoothProxy::parse_devices(const esp32_ble::BLEScanResult *scan_results, if (!api::global_api_server->is_connected() || this->api_connection_ == nullptr) return false; + auto &advertisements = this->response_.advertisements; + for (size_t i = 0; i < count; i++) { auto &result = scan_results[i]; uint8_t length = result.adv_data_len + result.scan_rsp_len; - // Check if we're at capacity - if (this->response_.advertisements_len >= BLUETOOTH_PROXY_ADVERTISEMENT_BATCH_SIZE) { - // Flush the batch before adding more - this->flush_pending_advertisements(); - } - // Fill in the data directly at current position - auto &adv = this->response_.advertisements[this->response_.advertisements_len]; + auto &adv = advertisements[this->response_.advertisements_len]; adv.address = esp32_ble::ble_addr_to_uint64(result.bda); adv.rssi = result.rssi; adv.address_type = result.ble_addr_type; @@ -93,6 +89,11 @@ bool BluetoothProxy::parse_devices(const esp32_ble::BLEScanResult *scan_results, ESP_LOGV(TAG, "Queuing raw packet from %02X:%02X:%02X:%02X:%02X:%02X, length %d. RSSI: %d dB", result.bda[0], result.bda[1], result.bda[2], result.bda[3], result.bda[4], result.bda[5], length, result.rssi); + + // Flush if we have reached BLUETOOTH_PROXY_ADVERTISEMENT_BATCH_SIZE + if (this->response_.advertisements_len >= BLUETOOTH_PROXY_ADVERTISEMENT_BATCH_SIZE) { + this->flush_pending_advertisements(); + } } return true; diff --git a/requirements.txt b/requirements.txt index 5e2773a71b..009a6850e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ platformio==6.1.18 # When updating platformio, also update /docker/Dockerfile esptool==5.0.2 click==8.1.7 esphome-dashboard==20250514.0 -aioesphomeapi==38.0.0 +aioesphomeapi==38.1.0 zeroconf==0.147.0 puremagic==1.30 ruamel.yaml==0.18.14 # dashboard_import diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index fff0ab56ca..3396e5ad05 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -1057,7 +1057,7 @@ def _generate_array_dump_content( """ o = f"for (const auto {'' if is_bool else '&'}it : {field_name}) {{\n" # Check if underlying type can use dump_field - if type(ti).can_use_dump_field(): + if ti.can_use_dump_field(): # For types that have dump_field overloads, use them with extra indent o += f' dump_field(out, "{name}", {ti.dump_field_value("it")}, 4);\n' else: @@ -1267,7 +1267,7 @@ class FixedArrayWithLengthRepeatedType(FixedArrayRepeatedType): # Dump only the active elements o = f"for (uint16_t i = 0; i < this->{self.field_name}_len; i++) {{\n" # Check if underlying type can use dump_field - if type(self._ti).can_use_dump_field(): + if self._ti.can_use_dump_field(): o += f' dump_field(out, "{self.name}", {self._ti.dump_field_value(f"this->{self.field_name}[i]")}, 4);\n' else: o += f' out.append(" {self.name}: ");\n'