ESPHome  2022.11.5
entity_base.cpp
Go to the documentation of this file.
2 #include "esphome/core/helpers.h"
3 
4 namespace esphome {
5 
6 static const char *const TAG = "entity_base";
7 
8 EntityBase::EntityBase(std::string name) : name_(std::move(name)) { this->calc_object_id_(); }
9 
10 // Entity Name
11 const std::string &EntityBase::get_name() const { return this->name_; }
12 void EntityBase::set_name(const std::string &name) {
13  this->name_ = name;
14  this->calc_object_id_();
15 }
16 
17 // Entity Internal
18 bool EntityBase::is_internal() const { return this->internal_; }
19 void EntityBase::set_internal(bool internal) { this->internal_ = internal; }
20 
21 // Entity Disabled by Default
23 void EntityBase::set_disabled_by_default(bool disabled_by_default) { this->disabled_by_default_ = disabled_by_default; }
24 
25 // Entity Icon
26 const std::string &EntityBase::get_icon() const { return this->icon_; }
27 void EntityBase::set_icon(const std::string &name) { this->icon_ = name; }
28 
29 // Entity Category
31 void EntityBase::set_entity_category(EntityCategory entity_category) { this->entity_category_ = entity_category; }
32 
33 // Entity Object ID
34 const std::string &EntityBase::get_object_id() { return this->object_id_; }
35 
36 // Calculate Object ID Hash from Entity Name
39  // FNV-1 hash
40  this->object_id_hash_ = fnv1_hash(this->object_id_);
41 }
42 uint32_t EntityBase::get_object_id_hash() { return this->object_id_hash_; }
43 
44 } // namespace esphome
void set_disabled_by_default(bool disabled_by_default)
Definition: entity_base.cpp:23
const char * name
Definition: stm32flash.h:78
std::string str_snake_case(const std::string &str)
Convert the string to snake case (lowercase with underscores).
Definition: helpers.cpp:160
const std::string & get_object_id()
Definition: entity_base.cpp:34
void set_internal(bool internal)
Definition: entity_base.cpp:19
std::string name_
Definition: entity_base.h:54
STL namespace.
std::string icon_
Definition: entity_base.h:56
void set_name(const std::string &name)
Definition: entity_base.cpp:12
const std::string & get_name() const
Definition: entity_base.cpp:11
const std::string & get_icon() const
Definition: entity_base.cpp:26
EntityCategory entity_category_
Definition: entity_base.h:60
void set_icon(const std::string &name)
Definition: entity_base.cpp:27
bool is_internal() const
Definition: entity_base.cpp:18
EntityCategory
Definition: entity_base.h:8
uint32_t object_id_hash_
Definition: entity_base.h:57
EntityCategory get_entity_category() const
Definition: entity_base.cpp:30
std::string str_sanitize(const std::string &str)
Sanitizes the input string by removing all characters but alphanumerics, dashes and underscores...
Definition: helpers.cpp:167
uint32_t fnv1_hash(const std::string &str)
Calculate a FNV-1 hash of str.
Definition: helpers.cpp:86
Definition: a4988.cpp:4
std::string object_id_
Definition: entity_base.h:55
bool is_disabled_by_default() const
Definition: entity_base.cpp:22
uint32_t get_object_id_hash()
Definition: entity_base.cpp:42
void set_entity_category(EntityCategory entity_category)
Definition: entity_base.cpp:31