ESPHome  2023.3.1
entity_base.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <cstdint>
5 
6 namespace esphome {
7 
8 enum EntityCategory : uint8_t {
12 };
13 
14 // The generic Entity base class that provides an interface common to all Entities.
15 class EntityBase {
16  public:
18  explicit EntityBase(std::string name);
19 
20  // Get/set the name of this Entity
21  const std::string &get_name() const;
22  void set_name(const std::string &name);
23 
24  // Get the sanitized name of this Entity as an ID. Caching it internally.
25  const std::string &get_object_id();
26 
27  // Get the unique Object ID of this Entity
28  uint32_t get_object_id_hash();
29 
30  // Get/set whether this Entity should be hidden from outside of ESPHome
31  bool is_internal() const;
32  void set_internal(bool internal);
33 
34  // Check if this object is declared to be disabled by default.
35  // That means that when the device gets added to Home Assistant (or other clients) it should
36  // not be added to the default view by default, and a user action is necessary to manually add it.
37  bool is_disabled_by_default() const;
38  void set_disabled_by_default(bool disabled_by_default);
39 
40  // Get/set the entity category.
42  void set_entity_category(EntityCategory entity_category);
43 
44  // Get/set this entity's icon
45  const std::string &get_icon() const;
46  void set_icon(const std::string &name);
47 
48  protected:
51  virtual uint32_t hash_base() { return 0L; }
52  void calc_object_id_();
53 
54  std::string name_;
55  std::string object_id_;
56  std::string icon_;
57  uint32_t object_id_hash_;
58  bool internal_{false};
59  bool disabled_by_default_{false};
61 };
62 
63 } // namespace esphome
void set_disabled_by_default(bool disabled_by_default)
Definition: entity_base.cpp:23
const char * name
Definition: stm32flash.h:78
const std::string & get_object_id()
Definition: entity_base.cpp:34
virtual uint32_t hash_base()
The hash_base() function has been deprecated.
Definition: entity_base.h:51
void set_internal(bool internal)
Definition: entity_base.cpp:19
std::string name_
Definition: entity_base.h:54
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
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