1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-09 14:52:20 +01:00

Allow entity names to be set to None (#4607)

* Allow entity names to be set to None so they take on the device friendly_name automatically

* Use empty
This commit is contained in:
Jesse Hills
2023-03-27 11:49:09 +13:00
committed by GitHub
parent 56504692af
commit c2756d57d8
5 changed files with 67 additions and 24 deletions

View File

@@ -1,4 +1,5 @@
#include "esphome/core/entity_base.h"
#include "esphome/core/application.h"
#include "esphome/core/helpers.h"
namespace esphome {
@@ -10,7 +11,13 @@ EntityBase::EntityBase(std::string name) : name_(std::move(name)) { this->calc_o
// Entity Name
const std::string &EntityBase::get_name() const { return this->name_; }
void EntityBase::set_name(const std::string &name) {
this->name_ = name;
if (name.empty()) {
this->name_ = App.get_friendly_name();
this->has_own_name_ = false;
} else {
this->name_ = name;
this->has_own_name_ = true;
}
this->calc_object_id_();
}