9static const char *
const TAG =
"entity_base";
26 this->
name_ = friendly;
38 if (object_id_hash != 0) {
45#ifdef USE_ENTITY_DEVICE_CLASS
48#ifdef USE_ENTITY_UNIT_OF_MEASUREMENT
49 this->
uom_idx_ = (entity_fields >> ENTITY_FIELD_UOM_SHIFT) & 0xFF;
52 this->
icon_idx_ = (entity_fields >> ENTITY_FIELD_ICON_SHIFT) & 0xFF;
54 this->
flags_.
internal = (entity_fields >> ENTITY_FIELD_INTERNAL_SHIFT) & 1;
66#ifdef USE_ENTITY_DEVICE_CLASS
69 const uint8_t idx = 0;
75 ESPHOME_strncpy_P(buffer.data(), dc, buffer.size() - 1);
76 buffer[buffer.size() - 1] =
'\0';
86#ifdef USE_ENTITY_DEVICE_CLASS
93#ifdef USE_ENTITY_DEVICE_CLASS
103#ifdef USE_ENTITY_UNIT_OF_MEASUREMENT
109std::string EntityBase::get_unit_of_measurement()
const {
115#ifdef USE_ENTITY_ICON
118 const uint8_t idx = 0;
124 ESPHOME_strncpy_P(buffer.data(), icon, buffer.size() - 1);
125 buffer[buffer.size() - 1] =
'\0';
126 return buffer.data();
135#ifdef USE_ENTITY_ICON
142#ifdef USE_ENTITY_ICON
151std::string EntityBase::get_object_id()
const {
152 char buf[OBJECT_ID_MAX_LEN];
154 return std::string(buf,
len);
163 size_t len = std::min(this->
name_.
size(), buf_size - 1);
164 for (
size_t i = 0; i <
len; i++) {
211#pragma GCC diagnostic push
212#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
213 uint32_t key = this->get_preference_hash() ^ version;
214#pragma GCC diagnostic pop
218#ifdef USE_ENTITY_ICON
220 char icon_buf[MAX_ICON_LENGTH];
222 if (icon[0] !=
'\0') {
223 ESP_LOGCONFIG(
tag,
"%s Icon: '%s'", prefix, icon);
229 char dc_buf[MAX_DEVICE_CLASS_LENGTH];
232 ESP_LOGCONFIG(
tag,
"%s Device Class: '%s'", prefix, dc);
const StringRef & get_name() const
Get the name of this Application set by pre_setup().
const StringRef & get_friendly_name() const
Get the friendly name of this Application set by pre_setup().
bool is_name_add_mac_suffix_enabled() const
struct esphome::EntityBase::EntityFlags flags_
ESPPreferenceObject make_entity_preference_(size_t size, uint32_t version)
Non-template helper for make_entity_preference() to avoid code bloat.
const char * get_device_class_to(std::span< char, MAX_DEVICE_CLASS_LENGTH > buffer) const
StringRef get_icon_ref() const
std::string get_device_class() const
ESPDEPRECATED("Use get_unit_of_measurement_ref() instead for better performance (avoids string copy). Will be " "removed in ESPHome 2026.9.0", "2026.3.0") std const char * get_icon_to(std::span< char, MAX_ICON_LENGTH > buffer) const
Get the unit of measurement as std::string (deprecated, prefer get_unit_of_measurement_ref())
std::string get_icon() 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...
uint8_t device_class_idx_
StringRef get_device_class_ref() const
ESPDEPRECATED("Use get_device_class_to() instead. Will be removed in ESPHome 2026.9.0", "2026.3.0") std StringRef get_unit_of_measurement_ref() const
void configure_entity_(const char *name, uint32_t object_id_hash, uint32_t entity_fields)
Combined entity setup from codegen: set name, object_id hash, entity string indices,...
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...
StringRef is a reference to a string owned by something else.
constexpr const char * c_str() const
constexpr bool empty() const
constexpr size_type size() const
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Providing packet encoding functions for exchanging data with a remote host.
void log_entity_icon(const char *tag, const char *prefix, const EntityBase &obj)
constexpr char to_sanitized_char(char c)
Sanitize a single char: keep alphanumerics, dashes, underscores; replace others with underscore.
void log_entity_unit_of_measurement(const char *tag, const char *prefix, const EntityBase &obj)
const char * entity_device_class_lookup(uint8_t index)
ESPPreferences * global_preferences
uint32_t fnv1_hash_object_id(const char *str, size_t len)
Calculate FNV-1 hash of a string while applying snake_case + sanitize transformations.
const char * entity_uom_lookup(uint8_t index)
const char * entity_icon_lookup(uint8_t index)
constexpr char to_snake_case_char(char c)
Convert a single char to snake_case: lowercase and space to underscore.
Application App
Global storage of Application pointer - only one Application can exist.
void log_entity_device_class(const char *tag, const char *prefix, const EntityBase &obj)
uint8_t disabled_by_default
ESPPreferenceObject make_preference(size_t, uint32_t, bool)