mirror of
https://github.com/esphome/esphome.git
synced 2025-11-20 16:55:49 +00:00
[core] Reduce flash size by combining set_name() and set_object_id() calls
This commit is contained in:
@@ -74,6 +74,12 @@ void EntityBase::set_object_id(const char *object_id) {
|
|||||||
this->calc_object_id_();
|
this->calc_object_id_();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityBase::set_name_and_object_id(const char *name, const char *object_id) {
|
||||||
|
this->set_name(name);
|
||||||
|
this->object_id_c_str_ = object_id;
|
||||||
|
this->calc_object_id_();
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate Object ID Hash from Entity Name
|
// Calculate Object ID Hash from Entity Name
|
||||||
void EntityBase::calc_object_id_() {
|
void EntityBase::calc_object_id_() {
|
||||||
this->object_id_hash_ =
|
this->object_id_hash_ =
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ class EntityBase {
|
|||||||
std::string get_object_id() const;
|
std::string get_object_id() const;
|
||||||
void set_object_id(const char *object_id);
|
void set_object_id(const char *object_id);
|
||||||
|
|
||||||
|
// Set both name and object_id in one call (reduces generated code size)
|
||||||
|
void set_name_and_object_id(const char *name, const char *object_id);
|
||||||
|
|
||||||
// Get the unique Object ID of this Entity
|
// Get the unique Object ID of this Entity
|
||||||
uint32_t get_object_id_hash();
|
uint32_t get_object_id_hash();
|
||||||
|
|
||||||
|
|||||||
@@ -84,8 +84,6 @@ async def setup_entity(var: MockObj, config: ConfigType, platform: str) -> None:
|
|||||||
# Get device name for object ID calculation
|
# Get device name for object ID calculation
|
||||||
device_name = device_id_obj.id
|
device_name = device_id_obj.id
|
||||||
|
|
||||||
add(var.set_name(config[CONF_NAME]))
|
|
||||||
|
|
||||||
# Calculate base object_id using the same logic as C++
|
# Calculate base object_id using the same logic as C++
|
||||||
# This must match the C++ behavior in esphome/core/entity_base.cpp
|
# This must match the C++ behavior in esphome/core/entity_base.cpp
|
||||||
base_object_id = get_base_entity_object_id(
|
base_object_id = get_base_entity_object_id(
|
||||||
@@ -97,8 +95,8 @@ async def setup_entity(var: MockObj, config: ConfigType, platform: str) -> None:
|
|||||||
"Entity has empty name, using '%s' as object_id base", base_object_id
|
"Entity has empty name, using '%s' as object_id base", base_object_id
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set the object ID
|
# Set both name and object_id in one call to reduce generated code size
|
||||||
add(var.set_object_id(base_object_id))
|
add(var.set_name_and_object_id(config[CONF_NAME], base_object_id))
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Setting object_id '%s' for entity '%s' on platform '%s'",
|
"Setting object_id '%s' for entity '%s' on platform '%s'",
|
||||||
base_object_id,
|
base_object_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user