mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 18:46:02 +00:00
Use auto for App.get_name()/get_friendly_name() bindings
This commit is contained in:
@@ -269,7 +269,7 @@ APIError APINoiseFrameHelper::state_action_() {
|
||||
}
|
||||
if (state_ == State::SERVER_HELLO) {
|
||||
// send server hello
|
||||
const StringRef &name = App.get_name();
|
||||
const auto &name = App.get_name();
|
||||
char mac[MAC_ADDRESS_BUFFER_SIZE];
|
||||
get_mac_address_into_buffer(mac);
|
||||
|
||||
|
||||
@@ -273,7 +273,7 @@ bool ESP32BLE::ble_setup_() {
|
||||
device_name = this->name_;
|
||||
}
|
||||
} else {
|
||||
const StringRef &app_name = App.get_name();
|
||||
const auto &app_name = App.get_name();
|
||||
size_t name_len = app_name.length();
|
||||
if (name_len > 20) {
|
||||
if (App.is_name_add_mac_suffix_enabled()) {
|
||||
|
||||
@@ -59,7 +59,7 @@ void MDNSComponent::compile_records_(StaticVector<MDNSService, MDNS_SERVICE_COUN
|
||||
service.proto = MDNS_STR(SERVICE_TCP);
|
||||
service.port = api::global_api_server->get_port();
|
||||
|
||||
const StringRef &friendly_name = App.get_friendly_name();
|
||||
const auto &friendly_name = App.get_friendly_name();
|
||||
bool friendly_name_empty = friendly_name.empty();
|
||||
|
||||
// Calculate exact capacity for txt_records
|
||||
|
||||
@@ -268,7 +268,7 @@ bool MQTTComponent::send_discovery_() {
|
||||
root[MQTT_UNIQUE_ID] = unique_id_buf;
|
||||
}
|
||||
|
||||
const StringRef &node_name = App.get_name();
|
||||
const auto &node_name = App.get_name();
|
||||
if (discovery_info.object_id_generator == MQTT_DEVICE_NAME_OBJECT_ID_GENERATOR) {
|
||||
// node_name (max 31) + "_" (1) + object_id (max 128) + null
|
||||
char object_id_full[ESPHOME_DEVICE_NAME_MAX_LEN + 1 + OBJECT_ID_MAX_LEN + 1];
|
||||
@@ -276,8 +276,8 @@ bool MQTTComponent::send_discovery_() {
|
||||
root[MQTT_OBJECT_ID] = object_id_full;
|
||||
}
|
||||
|
||||
const StringRef &friendly_name_ref = App.get_friendly_name();
|
||||
const StringRef &node_friendly_name = friendly_name_ref.empty() ? node_name : friendly_name_ref;
|
||||
const auto &friendly_name_ref = App.get_friendly_name();
|
||||
const auto &node_friendly_name = friendly_name_ref.empty() ? node_name : friendly_name_ref;
|
||||
const char *node_area = App.get_area();
|
||||
|
||||
JsonObject device_info = root[MQTT_DEVICE].to<JsonObject>();
|
||||
|
||||
@@ -132,7 +132,7 @@ void OpenThreadSrpComponent::setup() {
|
||||
// set the host name
|
||||
uint16_t size;
|
||||
char *existing_host_name = otSrpClientBuffersGetHostNameString(instance, &size);
|
||||
const StringRef &host_name = App.get_name();
|
||||
const auto &host_name = App.get_name();
|
||||
uint16_t host_name_len = host_name.size();
|
||||
if (host_name_len > size) {
|
||||
ESP_LOGW(TAG, "Hostname is too long, choose a shorter project name");
|
||||
|
||||
@@ -75,7 +75,7 @@ void WebServer::set_js_url(const char *js_url) { this->js_url_ = js_url; }
|
||||
|
||||
void WebServer::handle_index_request(AsyncWebServerRequest *request) {
|
||||
AsyncResponseStream *stream = request->beginResponseStream(ESPHOME_F("text/html"));
|
||||
const StringRef &title = App.get_name();
|
||||
const auto &title = App.get_name();
|
||||
stream->print(ESPHOME_F("<!DOCTYPE html><html lang=\"en\"><head><meta charset=UTF-8><meta "
|
||||
"name=viewport content=\"width=device-width, initial-scale=1,user-scalable=no\"><title>"));
|
||||
stream->print(title.c_str());
|
||||
|
||||
@@ -913,7 +913,7 @@ void WiFiComponent::setup_ap_config_() {
|
||||
static constexpr size_t AP_SSID_PREFIX_LEN = 25;
|
||||
static constexpr size_t AP_SSID_SUFFIX_LEN = 7;
|
||||
|
||||
const StringRef &app_name = App.get_name();
|
||||
const auto &app_name = App.get_name();
|
||||
const char *name_ptr = app_name.c_str();
|
||||
size_t name_len = app_name.length();
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ network::IPAddresses WiFiComponent::wifi_sta_ip_addresses() {
|
||||
return addresses;
|
||||
}
|
||||
bool WiFiComponent::wifi_apply_hostname_() {
|
||||
const StringRef &hostname = App.get_name();
|
||||
const auto &hostname = App.get_name();
|
||||
bool ret = wifi_station_set_hostname(const_cast<char *>(hostname.c_str()));
|
||||
if (!ret) {
|
||||
ESP_LOGV(TAG, "Set hostname failed");
|
||||
|
||||
@@ -22,7 +22,7 @@ void EntityBase::set_name(const char *name, uint32_t object_id_hash) {
|
||||
// Bug-for-bug compatibility with OLD behavior:
|
||||
// - With MAC suffix: OLD code used App.get_friendly_name() directly (no fallback)
|
||||
// - Without MAC suffix: OLD code used pre-computed object_id with fallback to device name
|
||||
const StringRef &friendly = App.get_friendly_name();
|
||||
const auto &friendly = App.get_friendly_name();
|
||||
if (App.is_name_add_mac_suffix_enabled()) {
|
||||
// MAC suffix enabled - use friendly_name directly (even if empty) for compatibility
|
||||
this->name_ = friendly;
|
||||
|
||||
Reference in New Issue
Block a user