23NameCopy *name_copies =
nullptr;
24const StringRef EMPTY_NAME;
27const StringRef &EntityBase::get_name()
const {
29 for (NameCopy *copy = name_copies; copy !=
nullptr; copy = copy->next) {
34 void *mem = malloc(
sizeof(NameCopy) +
len + 1);
37 char *buf =
static_cast<char *
>(mem) +
sizeof(NameCopy);
39 name_copies =
new (mem) NameCopy{name_copies,
key, StringRef(buf,
len)};
40 return name_copies->ref;
73 if (object_id_hash == 0) {
77 return static_cast<char>(progmem_read_byte(reinterpret_cast<const uint8_t *>(name_p + i)));
83#ifdef USE_ENTITY_DEVICE_CLASS
86#ifdef USE_ENTITY_UNIT_OF_MEASUREMENT
87 this->
uom_idx_ = (entity_fields >> ENTITY_FIELD_UOM_SHIFT) & 0xFF;
90 this->
icon_idx_ = (entity_fields >> ENTITY_FIELD_ICON_SHIFT) & 0xFF;
92 this->
flags_.
internal = (entity_fields >> ENTITY_FIELD_INTERNAL_SHIFT) & 1;
100 ESP_LOGE(TAG,
"'%s': set_internal() after setup is undefined behavior, stops working in 2027.3.0",
111static ProgmemStringRef table_ref(
const char *s) {
return {s, ESPHOME_strlen_P(s)}; }
114#ifdef USE_ENTITY_DEVICE_CLASS
132#ifdef USE_ENTITY_UNIT_OF_MEASUREMENT
139#ifdef USE_ENTITY_ICON
157 for (
size_t i = 0; i <
len; i++) {
174#pragma GCC diagnostic push
175#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
176 return this->get_preference_hash() ^ version;
177#pragma GCC diagnostic pop
191 ESP_LOGCONFIG(tag,
"%s%s '%s'", prefix,
type, LOG_STR_ARG(obj->
get_log_name()));
195#ifdef USE_ENTITY_ICON
199 ESP_LOGCONFIG(tag,
"%s Icon: '%s'", prefix, icon.
progmem_ptr());
207 ESP_LOGCONFIG(tag,
"%s Device Class: '%s'", prefix, dc.
progmem_ptr());
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
bool is_setup_complete() const
True once Application::setup() has finished walking all components and finalized the initial status f...
struct esphome::EntityBase::EntityFlags flags_
ESPPreferenceObject make_entity_preference_(size_t size, uint32_t version)
Non-template helpers for make_entity_preference() to avoid code bloat.
const char * get_device_class_to(std::span< char, MAX_DEVICE_CLASS_LENGTH > buffer) const
ProgmemStringRef get_device_class_progmem() const
The device class as stored (in flash on ESP8266), for consumers that read flash themselves.
size_t write_name_to(char *buf, size_t buf_size) const
Copy the name into buf (null terminated), returns its length.
const char * get_icon_to(std::span< char, MAX_ICON_LENGTH > buffer) const
ProgmemStringRef get_icon_progmem() const
The icon as stored (in flash on ESP8266), for consumers that read flash themselves.
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_
uint32_t entity_preference_key_(uint32_t version)
Key for both helpers; preference hash migration goes here.
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
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...
void set_internal(bool internal)
A string that may live in flash (on ESP8266): pointer and length, with no byte-reading operations.
constexpr const char * progmem_ptr() const
size_t write_to(char *buf, size_t buf_size) const
Copy into buf (null terminated, truncated to fit), returns the length copied.
constexpr size_t size() const
constexpr bool empty() const
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 @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
ESPHOME_LOG_TAG(TAG, CRASH_LOG_TAG)
bool log_entity_header(const char *tag, const char *prefix, const char *type, const EntityBase *obj)
Log "<prefix><type> '<name>'" for a dump_config header; returns false when obj is null.
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(size_t len, ReadByte read_byte)
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)