17static constexpr size_t OBJECT_ID_MAX_LEN = 128;
40 ESPDEPRECATED(
"object_id mangles names and all object_id methods are planned for removal "
41 "(see https://github.com/esphome/backlog/issues/76). "
42 "Now is the time to stop using object_id. If still needed, use get_object_id_to() "
43 "which will remain available longer. get_object_id() will be removed in 2026.7.0",
45 std::
string get_object_id() const;
81 "Use get_icon_ref() instead for better performance (avoids string copy). Will be removed in ESPHome 2026.5.0",
83 std::
string get_icon() const;
148#ifdef USE_ENTITY_ICON
170 ESPDEPRECATED(
"Use get_device_class_ref() instead for better performance (avoids string copy). Will be removed in "
173 std::string get_device_class();
189 ESPDEPRECATED(
"Use get_unit_of_measurement_ref() instead for better performance (avoids string copy). Will be "
190 "removed in ESPHome 2026.5.0",
192 std::string get_unit_of_measurement();
240 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)
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 void set_object_id(const char *object_id)
bool has_own_name() const
const char * object_id_c_str_
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
bool is_object_id_dynamic_() const
Check if the object_id is dynamic (changes with MAC suffix)
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)
void set_disabled_by_default(bool disabled_by_default)
void set_has_state(bool state)
void set_name_and_object_id(const char *name, const char *object_id)
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