From 0b004a7d9b97afb56c01193649f1330b13d4214e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 16 Aug 2025 09:38:00 -0400 Subject: [PATCH] tweak --- esphome/core/entity_base.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/esphome/core/entity_base.cpp b/esphome/core/entity_base.cpp index 97bf7147b5..411a877bbf 100644 --- a/esphome/core/entity_base.cpp +++ b/esphome/core/entity_base.cpp @@ -51,22 +51,18 @@ std::string EntityBase::get_object_id() const { if (!this->flags_.has_own_name && App.is_name_add_mac_suffix_enabled()) { // `App.get_friendly_name()` is dynamic. return str_sanitize(str_snake_case(App.get_friendly_name())); - } else { - // `App.get_friendly_name()` is constant. - if (this->object_id_c_str_ == nullptr) { - return ""; - } - return this->object_id_c_str_; } + // `App.get_friendly_name()` is constant. + return this->object_id_c_str_ == nullptr ? "" : this->object_id_c_str_; } StringRef EntityBase::get_object_id_ref_for_api_() const { - static constexpr auto EMPTY_STRING_REF = StringRef::from_lit(""); + static constexpr auto EMPTY_STRING = StringRef::from_lit(""); // Return empty for dynamic case (MAC suffix) if (!this->flags_.has_own_name && App.is_name_add_mac_suffix_enabled()) { - return EMPTY_STRING_REF; + return EMPTY_STRING; } // For static case, return the string or empty if null - return this->object_id_c_str_ == nullptr ? EMPTY_STRING_REF : StringRef(this->object_id_c_str_); + return this->object_id_c_str_ == nullptr ? EMPTY_STRING : StringRef(this->object_id_c_str_); } void EntityBase::set_object_id(const char *object_id) { this->object_id_c_str_ = object_id;