mirror of
https://github.com/esphome/esphome.git
synced 2025-09-01 19:02:18 +01:00
tweak
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user