1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 15:55:46 +00:00

Revert "free"

This reverts commit fbc3413ed9.
This commit is contained in:
J. Nick Koston
2025-11-05 23:47:28 -06:00
parent fbc3413ed9
commit 1e58c400ea
17 changed files with 40 additions and 43 deletions

View File

@@ -11,7 +11,7 @@ static const char *const TAG = "binary_sensor";
void log_binary_sensor(const char *tag, const char *prefix, const char *type, BinarySensor *obj) {
if (obj != nullptr) {
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
log_entity_device_class(tag, prefix, obj);
obj->log_device_class(tag, prefix);
}
}

View File

@@ -10,7 +10,7 @@ static const char *const TAG = "button";
void log_button(const char *tag, const char *prefix, const char *type, Button *obj) {
if (obj != nullptr) {
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
log_entity_icon(tag, prefix, obj);
obj->log_icon(tag, prefix);
}
}

View File

@@ -20,7 +20,7 @@ const extern float COVER_CLOSED;
if (traits_.get_is_assumed_state()) { \
ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \
} \
log_entity_device_class(TAG, prefix, (obj)); \
(obj)->log_device_class(TAG, prefix); \
}
class Cover;

View File

@@ -16,7 +16,7 @@ namespace datetime {
#define LOG_DATETIME_DATE(prefix, type, obj) \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
log_entity_icon(TAG, prefix, (obj)); \
(obj)->log_icon(TAG, prefix); \
}
class DateCall;

View File

@@ -16,7 +16,7 @@ namespace datetime {
#define LOG_DATETIME_DATETIME(prefix, type, obj) \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
log_entity_icon(TAG, prefix, (obj)); \
(obj)->log_icon(TAG, prefix); \
}
class DateTimeCall;

View File

@@ -16,7 +16,7 @@ namespace datetime {
#define LOG_DATETIME_TIME(prefix, type, obj) \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
log_entity_icon(TAG, prefix, (obj)); \
(obj)->log_icon(TAG, prefix); \
}
class TimeCall;

View File

@@ -12,8 +12,8 @@ namespace event {
#define LOG_EVENT(prefix, type, obj) \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
log_entity_icon(TAG, prefix, (obj)); \
log_entity_device_class(TAG, prefix, (obj)); \
(obj)->log_icon(TAG, prefix); \
(obj)->log_device_class(TAG, prefix); \
}
class Event : public EntityBase, public EntityBase_DeviceClass {

View File

@@ -15,7 +15,7 @@ class Lock;
#define LOG_LOCK(prefix, type, obj) \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
log_entity_icon(TAG, prefix, (obj)); \
(obj)->log_icon(TAG, prefix); \
if ((obj)->traits.get_assumed_state()) { \
ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \
} \

View File

@@ -10,13 +10,13 @@ static const char *const TAG = "number";
void log_number(const char *tag, const char *prefix, const char *type, Number *obj) {
if (obj != nullptr) {
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
log_entity_icon(tag, prefix, obj);
obj->log_icon(tag, prefix);
if (!obj->traits.get_unit_of_measurement_ref().empty()) {
ESP_LOGCONFIG(tag, "%s Unit of Measurement: '%s'", prefix, obj->traits.get_unit_of_measurement_ref().c_str());
}
log_entity_device_class(tag, prefix, &obj->traits);
obj->traits.log_device_class(tag, prefix);
}
}

View File

@@ -12,7 +12,7 @@ namespace select {
#define LOG_SELECT(prefix, type, obj) \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
log_entity_icon(TAG, prefix, (obj)); \
(obj)->log_icon(TAG, prefix); \
}
#define SUB_SELECT(name) \

View File

@@ -18,8 +18,8 @@ void log_sensor(const char *tag, const char *prefix, const char *type, Sensor *o
LOG_STR_ARG(state_class_to_string(obj->get_state_class())), prefix,
obj->get_unit_of_measurement_ref().c_str(), prefix, obj->get_accuracy_decimals());
log_entity_device_class(tag, prefix, obj);
log_entity_icon(tag, prefix, obj);
obj->log_device_class(tag, prefix);
obj->log_icon(tag, prefix);
if (obj->get_force_update()) {
ESP_LOGV(tag, "%s Force Update: YES", prefix);

View File

@@ -91,14 +91,14 @@ void log_switch(const char *tag, const char *prefix, const char *type, Switch *o
LOG_STR_ARG(onoff));
// Add optional fields separately
log_entity_icon(tag, prefix, obj);
obj->log_icon(tag, prefix);
if (obj->assumed_state()) {
ESP_LOGCONFIG(tag, "%s Assumed State: YES", prefix);
}
if (obj->is_inverted()) {
ESP_LOGCONFIG(tag, "%s Inverted: YES", prefix);
}
log_entity_device_class(tag, prefix, obj);
obj->log_device_class(tag, prefix);
}
}

View File

@@ -12,7 +12,7 @@ namespace text {
#define LOG_TEXT(prefix, type, obj) \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
log_entity_icon(TAG, prefix, (obj)); \
(obj)->log_icon(TAG, prefix); \
}
/** Base-class for all text inputs.

View File

@@ -9,8 +9,8 @@ static const char *const TAG = "text_sensor";
void log_text_sensor(const char *tag, const char *prefix, const char *type, TextSensor *obj) {
if (obj != nullptr) {
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
log_entity_device_class(tag, prefix, obj);
log_entity_icon(tag, prefix, obj);
obj->log_device_class(tag, prefix);
obj->log_icon(tag, prefix);
}
}

View File

@@ -19,7 +19,7 @@ const extern float VALVE_CLOSED;
if (traits_.get_is_assumed_state()) { \
ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \
} \
log_entity_device_class(TAG, prefix, (obj)); \
(obj)->log_device_class(TAG, prefix); \
}
class Valve;

View File

@@ -45,6 +45,14 @@ void EntityBase::set_icon(const char *icon) {
#endif
}
void EntityBase::log_icon(const char *tag, const char *prefix) const {
#ifdef USE_ENTITY_ICON
if (!this->get_icon_ref().empty()) {
ESP_LOGCONFIG(tag, "%s Icon: '%s'", prefix, this->get_icon_ref().c_str());
}
#endif
}
// Check if the object_id is dynamic (changes with MAC suffix)
bool EntityBase::is_object_id_dynamic_() const {
return !this->flags_.has_own_name && App.is_name_add_mac_suffix_enabled();
@@ -91,6 +99,12 @@ std::string EntityBase_DeviceClass::get_device_class() {
void EntityBase_DeviceClass::set_device_class(const char *device_class) { this->device_class_ = device_class; }
void EntityBase_DeviceClass::log_device_class(const char *tag, const char *prefix) const {
if (!this->get_device_class_ref().empty()) {
ESP_LOGCONFIG(tag, "%s Device Class: '%s'", prefix, this->get_device_class_ref().c_str());
}
}
std::string EntityBase_UnitOfMeasurement::get_unit_of_measurement() {
if (this->unit_of_measurement_ == nullptr)
return "";
@@ -100,19 +114,4 @@ void EntityBase_UnitOfMeasurement::set_unit_of_measurement(const char *unit_of_m
this->unit_of_measurement_ = unit_of_measurement;
}
// Helper functions for logging entity attributes
void log_entity_icon(const char *tag, const char *prefix, const EntityBase *obj) {
#ifdef USE_ENTITY_ICON
if (!obj->get_icon_ref().empty()) {
ESP_LOGCONFIG(tag, "%s Icon: '%s'", prefix, obj->get_icon_ref().c_str());
}
#endif
}
void log_entity_device_class(const char *tag, const char *prefix, const EntityBase_DeviceClass *obj) {
if (!obj->get_device_class_ref().empty()) {
ESP_LOGCONFIG(tag, "%s Device Class: '%s'", prefix, obj->get_device_class_ref().c_str());
}
}
} // namespace esphome

View File

@@ -74,6 +74,9 @@ class EntityBase {
#endif
}
/// Log entity icon if present (guarded by USE_ENTITY_ICON)
void log_icon(const char *tag, const char *prefix) const;
#ifdef USE_DEVICES
// Get/set this entity's device id
uint32_t get_device_id() const {
@@ -171,6 +174,9 @@ class EntityBase_DeviceClass { // NOLINT(readability-identifier-naming)
return this->device_class_ == nullptr ? EMPTY_STRING : StringRef(this->device_class_);
}
/// Log entity device class if present
void log_device_class(const char *tag, const char *prefix) const;
protected:
const char *device_class_{nullptr}; ///< Device class override
};
@@ -248,12 +254,4 @@ template<typename T> class StatefulEntityBase : public EntityBase {
CallbackManager<void(T)> *state_callbacks_{};
};
// Helper functions for logging entity attributes
/// Log entity icon if present (guarded by USE_ENTITY_ICON)
void log_entity_icon(const char *tag, const char *prefix, const EntityBase *obj);
/// Log entity device class if present
void log_entity_device_class(const char *tag, const char *prefix, const EntityBase_DeviceClass *obj);
} // namespace esphome