diff --git a/esphome/core/entity_base.cpp b/esphome/core/entity_base.cpp index e5231ed759..725a8569a3 100644 --- a/esphome/core/entity_base.cpp +++ b/esphome/core/entity_base.cpp @@ -35,15 +35,6 @@ std::string EntityBase::get_icon() const { } void EntityBase::set_icon(const char *icon) { this->icon_c_str_ = icon; } -// Entity Device id -const StringRef &EntityBase::get_device_id() const { - if (this->device_id_.empty()) { - return StringRef(""); - } - return this->device_id_; -} -void EntityBase::set_device_id(const std::string device_id) { this->device_id_ = StringRef(device_id); } - // Entity Category EntityCategory EntityBase::get_entity_category() const { return this->entity_category_; } void EntityBase::set_entity_category(EntityCategory entity_category) { this->entity_category_ = entity_category; } diff --git a/esphome/core/entity_base.h b/esphome/core/entity_base.h index e52406c425..e66fbb66e6 100644 --- a/esphome/core/entity_base.h +++ b/esphome/core/entity_base.h @@ -48,8 +48,8 @@ class EntityBase { void set_icon(const char *icon); // Get/set this entity's device id - const StringRef &get_device_id() const; - void set_device_id(const std::string device_id); + const StringRef &get_device_id() const { return this->device_id_; } + void set_device_id(const std::string &device_id) { this->device_id_ = StringRef(device_id); } protected: /// The hash_base() function has been deprecated. It is kept in this @@ -65,7 +65,7 @@ class EntityBase { bool internal_{false}; bool disabled_by_default_{false}; EntityCategory entity_category_{ENTITY_CATEGORY_NONE}; - StringRef device_id_; + StringRef device_id_{""}; }; class EntityBase_DeviceClass { // NOLINT(readability-identifier-naming)