17static constexpr size_t ESPHOME_DEVICE_NAME_MAX_LEN = 31;
21static constexpr size_t ESPHOME_FRIENDLY_NAME_MAX_LEN = 120;
24static constexpr size_t ESPHOME_DOMAIN_MAX_LEN = 20;
27static constexpr size_t OBJECT_ID_MAX_LEN = 128;
30static constexpr size_t MAX_STATE_LEN = 255;
46 void set_name(
const char *name, uint32_t object_id_hash);
56 ESPDEPRECATED(
"object_id mangles names and all object_id methods are planned for removal "
57 "(see https://github.com/esphome/backlog/issues/76). "
58 "Now is the time to stop using object_id. If still needed, use get_object_id_to() "
59 "which will remain available longer. get_object_id() will be removed in 2026.7.0",
61 std::
string get_object_id() const;
93 "Use get_icon_ref() instead for better performance (avoids string copy). Will be removed in ESPHome 2026.5.0",
95 std::
string get_icon() const;
109 if (this->
device_ ==
nullptr) {
158#ifdef USE_ENTITY_ICON
180 ESPDEPRECATED(
"Use get_device_class_ref() instead for better performance (avoids string copy). Will be removed in "
183 std::string get_device_class();
199 ESPDEPRECATED(
"Use get_unit_of_measurement_ref() instead for better performance (avoids string copy). Will be "
200 "removed in ESPHome 2026.5.0",
202 std::string get_unit_of_measurement();
250 if (this->
state_ != new_state) {
StringRef get_device_class_ref() const
Get the device class as StringRef.
ESPDEPRECATED("Use get_device_class_ref() instead for better performance (avoids string copy). Will be removed in " "ESPHome 2026.5.0", "2025.11.0") std void set_device_class(const char *device_class)
Get the device class, using the manual override if set.
const char * device_class_
Device class override.
const char * unit_of_measurement_
Unit of measurement override.
ESPDEPRECATED("Use get_unit_of_measurement_ref() instead for better performance (avoids string copy). Will be " "removed in ESPHome 2026.5.0", "2025.11.0") std void set_unit_of_measurement(const char *unit_of_measurement)
Get the unit of measurement, using the manual override if set.
StringRef get_unit_of_measurement_ref() const
Get the unit of measurement as StringRef.
struct esphome::EntityBase::EntityFlags flags_
void set_device(Device *device)
bool has_own_name() const
ESPDEPRECATED("object_id mangles names and all object_id methods are planned for removal " "(see https://github.com/esphome/backlog/issues/76). " "Now is the time to stop using object_id. If still needed, use get_object_id_to() " "which will remain available longer. get_object_id() will be removed in 2026.7.0", "2025.12.0") std uint32_t get_object_id_hash()
const StringRef & get_name() const
uint32_t get_preference_hash()
Get a unique hash for storing preferences/settings for this entity.
void set_entity_category(EntityCategory entity_category)
StringRef get_icon_ref() const
size_t write_object_id_to(char *buf, size_t buf_size) const
Write object_id directly to buffer, returns length written (excluding null) Useful for building compo...
uint32_t get_device_id() const
bool is_disabled_by_default() const
void set_name(const char *name)
ESPDEPRECATED("Use get_icon_ref() instead for better performance (avoids string copy). Will be removed in ESPHome 2026.5.0", "2025.11.0") std void set_icon(const char *icon)
Device * get_device() const
void set_disabled_by_default(bool disabled_by_default)
void set_has_state(bool state)
EntityCategory get_entity_category() const
StringRef get_object_id_to(std::span< char, OBJECT_ID_MAX_LEN > buf) const
Get object_id with zero heap allocation For static case: returns StringRef to internal storage (buffe...
void set_internal(bool internal)
An entity that has a state.
virtual const T & get_state() const
bool trigger_on_initial_state_
virtual bool set_new_state(const optional< T > &new_state)
Set a new state for this entity.
void add_full_state_callback(std::function< void(optional< T > previous, optional< T > current)> &&callback)
CallbackManager< void(T)> * state_callbacks_
void add_on_state_callback(std::function< void(T)> &&callback)
void set_trigger_on_initial_state(bool trigger_on_initial_state)
virtual bool has_state() const
virtual T get_state_default(T default_value) const
CallbackManager< void(optional< T > previous, optional< T > current)> * full_state_callbacks_
StringRef is a reference to a string owned by something else.
static constexpr StringRef from_lit(const CharT(&s)[N])
value_type const & value() const
Providing packet encoding functions for exchanging data with a remote host.
@ ENTITY_CATEGORY_DIAGNOSTIC
struct ESPDEPRECATED("Use std::index_sequence instead. Removed in 2026.6.0", "2025.12.0") seq
uint8_t disabled_by_default