1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-07 05:42:20 +01:00

[ble] Allow setting shorter name for ble advertisements (#7867)

Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
Jesse Hills
2024-12-03 18:38:44 +13:00
committed by GitHub
parent 584dbf2668
commit dc5942a59b
4 changed files with 38 additions and 8 deletions

View File

@@ -188,12 +188,20 @@ bool ESP32BLE::ble_setup_() {
}
}
std::string name = App.get_name();
if (name.length() > 20) {
std::string name;
if (this->name_.has_value()) {
name = this->name_.value();
if (App.is_name_add_mac_suffix_enabled()) {
name.erase(name.begin() + 13, name.end() - 7); // Remove characters between 13 and the mac address
} else {
name = name.substr(0, 20);
name += "-" + get_mac_address().substr(6);
}
} else {
name = App.get_name();
if (name.length() > 20) {
if (App.is_name_add_mac_suffix_enabled()) {
name.erase(name.begin() + 13, name.end() - 7); // Remove characters between 13 and the mac address
} else {
name = name.substr(0, 20);
}
}
}