mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
inline set_name/set_entity_strings directly into configure_entity
No separate functions needed — configure_entity is the only caller. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,8 +9,8 @@ static const char *const TAG = "entity_base";
|
||||
|
||||
// Entity Name
|
||||
const StringRef &EntityBase::get_name() const { return this->name_; }
|
||||
void EntityBase::set_name(const char *name) { this->set_name(name, 0); }
|
||||
void EntityBase::set_name(const char *name, uint32_t object_id_hash) {
|
||||
|
||||
void EntityBase::configure_entity(const char *name, uint32_t object_id_hash, uint32_t entity_strings_packed) {
|
||||
this->name_ = StringRef(name);
|
||||
if (this->name_.empty()) {
|
||||
#ifdef USE_DEVICES
|
||||
@@ -43,11 +43,15 @@ void EntityBase::set_name(const char *name, uint32_t object_id_hash) {
|
||||
this->calc_object_id_();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EntityBase::configure_entity(const char *name, uint32_t object_id_hash, uint32_t entity_strings_packed) {
|
||||
this->set_name(name, object_id_hash);
|
||||
this->set_entity_strings(entity_strings_packed);
|
||||
#ifdef USE_ENTITY_DEVICE_CLASS
|
||||
this->device_class_idx_ = entity_strings_packed & 0xFF;
|
||||
#endif
|
||||
#ifdef USE_ENTITY_UNIT_OF_MEASUREMENT
|
||||
this->uom_idx_ = (entity_strings_packed >> 8) & 0xFF;
|
||||
#endif
|
||||
#ifdef USE_ENTITY_ICON
|
||||
this->icon_idx_ = (entity_strings_packed >> 16) & 0xFF;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Weak default lookup functions — overridden by generated code in main.cpp
|
||||
|
||||
@@ -45,12 +45,8 @@ enum EntityCategory : uint8_t {
|
||||
// The generic Entity base class that provides an interface common to all Entities.
|
||||
class EntityBase {
|
||||
public:
|
||||
// Get/set the name of this Entity
|
||||
// Get the name of this Entity
|
||||
const StringRef &get_name() const;
|
||||
void set_name(const char *name);
|
||||
/// Set name with pre-computed object_id hash (avoids runtime hash calculation)
|
||||
/// Use hash=0 for dynamic names that need runtime calculation
|
||||
void set_name(const char *name, uint32_t object_id_hash);
|
||||
|
||||
/// Combined entity setup from codegen: set name, object_id hash, and entity string indices.
|
||||
void configure_entity(const char *name, uint32_t object_id_hash, uint32_t entity_strings_packed);
|
||||
@@ -98,20 +94,6 @@ class EntityBase {
|
||||
this->flags_.entity_category = static_cast<uint8_t>(entity_category);
|
||||
}
|
||||
|
||||
// Set entity string table indices — one call per entity from codegen.
|
||||
// Packed: [23..16] icon | [15..8] UoM | [7..0] device_class (each 8 bits)
|
||||
void set_entity_strings([[maybe_unused]] uint32_t packed) {
|
||||
#ifdef USE_ENTITY_DEVICE_CLASS
|
||||
this->device_class_idx_ = packed & 0xFF;
|
||||
#endif
|
||||
#ifdef USE_ENTITY_UNIT_OF_MEASUREMENT
|
||||
this->uom_idx_ = (packed >> 8) & 0xFF;
|
||||
#endif
|
||||
#ifdef USE_ENTITY_ICON
|
||||
this->icon_idx_ = (packed >> 16) & 0xFF;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Get device class as StringRef (from packed index)
|
||||
StringRef get_device_class_ref() const;
|
||||
/// Get the device class as std::string (deprecated, prefer get_device_class_ref())
|
||||
|
||||
Reference in New Issue
Block a user