1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 15:55:46 +00:00

Merge branch 'device_info_less_alloc' into integration

This commit is contained in:
J. Nick Koston
2025-11-17 09:36:02 -06:00
2 changed files with 10 additions and 8 deletions

View File

@@ -1451,8 +1451,11 @@ bool APIConnection::send_device_info_response(const DeviceInfoRequest &msg) {
#ifdef USE_AREAS #ifdef USE_AREAS
resp.set_suggested_area(StringRef(App.get_area())); resp.set_suggested_area(StringRef(App.get_area()));
#endif #endif
// mac_address must store temporary string - will be valid during send_message call // Stack buffer for MAC address (XX:XX:XX:XX:XX:XX\0 = 18 bytes)
std::string mac_address = get_mac_address_pretty(); char mac_address[18];
uint8_t mac[6];
get_mac_address_raw(mac);
format_mac_addr_upper(mac, mac_address);
resp.set_mac_address(StringRef(mac_address)); resp.set_mac_address(StringRef(mac_address));
resp.set_esphome_version(ESPHOME_VERSION_REF); resp.set_esphome_version(ESPHOME_VERSION_REF);
@@ -1493,8 +1496,9 @@ bool APIConnection::send_device_info_response(const DeviceInfoRequest &msg) {
#endif #endif
#ifdef USE_BLUETOOTH_PROXY #ifdef USE_BLUETOOTH_PROXY
resp.bluetooth_proxy_feature_flags = bluetooth_proxy::global_bluetooth_proxy->get_feature_flags(); resp.bluetooth_proxy_feature_flags = bluetooth_proxy::global_bluetooth_proxy->get_feature_flags();
// bt_mac must store temporary string - will be valid during send_message call // Stack buffer for Bluetooth MAC address (XX:XX:XX:XX:XX:XX\0 = 18 bytes)
std::string bluetooth_mac = bluetooth_proxy::global_bluetooth_proxy->get_bluetooth_mac_address_pretty(); char bluetooth_mac[18];
bluetooth_proxy::global_bluetooth_proxy->get_bluetooth_mac_address_pretty(bluetooth_mac);
resp.set_bluetooth_mac_address(StringRef(bluetooth_mac)); resp.set_bluetooth_mac_address(StringRef(bluetooth_mac));
#endif #endif
#ifdef USE_VOICE_ASSISTANT #ifdef USE_VOICE_ASSISTANT

View File

@@ -130,11 +130,9 @@ class BluetoothProxy final : public esp32_ble_tracker::ESPBTDeviceListener, publ
return flags; return flags;
} }
std::string get_bluetooth_mac_address_pretty() { void get_bluetooth_mac_address_pretty(std::span<char, 18> output) {
const uint8_t *mac = esp_bt_dev_get_address(); const uint8_t *mac = esp_bt_dev_get_address();
char buf[18]; format_mac_addr_upper(mac, output.data());
format_mac_addr_upper(mac, buf);
return std::string(buf);
} }
protected: protected: