From 1b8b8cdd11eb8adf6ac152a6d8fcd41e8bad7606 Mon Sep 17 00:00:00 2001 From: Fabian Date: Wed, 15 Mar 2023 23:20:12 +0100 Subject: [PATCH] EntityBase: Icon string can stay in flash. (#4566) * Icon string can stay in flash. * Remove redundant const. --------- Co-authored-by: Your Name --- esphome/core/entity_base.cpp | 9 +++++++-- esphome/core/entity_base.h | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/esphome/core/entity_base.cpp b/esphome/core/entity_base.cpp index a9e1414018..6f88f069b3 100644 --- a/esphome/core/entity_base.cpp +++ b/esphome/core/entity_base.cpp @@ -23,8 +23,13 @@ bool EntityBase::is_disabled_by_default() const { return this->disabled_by_defau void EntityBase::set_disabled_by_default(bool disabled_by_default) { this->disabled_by_default_ = disabled_by_default; } // Entity Icon -const std::string &EntityBase::get_icon() const { return this->icon_; } -void EntityBase::set_icon(const std::string &name) { this->icon_ = name; } +std::string EntityBase::get_icon() const { + if (this->icon_c_str_ == nullptr) { + return ""; + } + return this->icon_c_str_; +} +void EntityBase::set_icon(const char *icon) { this->icon_c_str_ = icon; } // Entity Category EntityCategory EntityBase::get_entity_category() const { return this->entity_category_; } diff --git a/esphome/core/entity_base.h b/esphome/core/entity_base.h index a9eedfd07e..f6aae4e978 100644 --- a/esphome/core/entity_base.h +++ b/esphome/core/entity_base.h @@ -42,8 +42,8 @@ class EntityBase { void set_entity_category(EntityCategory entity_category); // Get/set this entity's icon - const std::string &get_icon() const; - void set_icon(const std::string &name); + std::string get_icon() const; + void set_icon(const char *icon); protected: /// The hash_base() function has been deprecated. It is kept in this @@ -53,7 +53,7 @@ class EntityBase { std::string name_; std::string object_id_; - std::string icon_; + const char *icon_c_str_{nullptr}; uint32_t object_id_hash_; bool internal_{false}; bool disabled_by_default_{false};