8static const char *
const TAG =
"entity_base";
30std::string EntityBase::get_icon()
const {
54std::string EntityBase::get_object_id()
const {
76 char buf[OBJECT_ID_MAX_LEN];
82static size_t format_dynamic_object_id(
char *buf,
size_t buf_size) {
84 size_t len = std::min(name.size(), buf_size - 1);
85 for (
size_t i = 0; i <
len; i++) {
94 return format_dynamic_object_id(buf, buf_size);
97 size_t len = strlen(src);
100 memcpy(buf, src,
len);
107 size_t len = format_dynamic_object_id(buf.data(), buf.size());
115std::string EntityBase_DeviceClass::get_device_class() {
124std::string EntityBase_UnitOfMeasurement::get_unit_of_measurement() {
const std::string & get_friendly_name() const
Get the friendly name of this Application set by pre_setup().
bool is_name_add_mac_suffix_enabled() const
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.
struct esphome::EntityBase::EntityFlags flags_
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)
const char * object_id_c_str_
uint32_t get_object_id_hash()
const StringRef & get_name() 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...
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_name_and_object_id(const char *name, const char *object_id)
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
Providing packet encoding functions for exchanging data with a remote host.
constexpr char to_sanitized_char(char c)
Sanitize a single char: keep alphanumerics, dashes, underscores; replace others with underscore.
std::string str_sanitize(const std::string &str)
Sanitizes the input string by removing all characters but alphanumerics, dashes and underscores.
uint32_t fnv1_hash(const char *str)
Calculate a FNV-1 hash of str.
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.
std::string str_snake_case(const std::string &str)
Convert the string to snake case (lowercase with underscores).