From 3d789f9ccce81b8c598a9657aae696d58d103388 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 27 Jan 2026 17:29:02 -1000 Subject: [PATCH] tweak --- .../components/binary_sensor/binary_sensor.cpp | 2 +- esphome/components/button/button.cpp | 2 +- esphome/components/cover/cover.h | 2 +- esphome/components/datetime/date_entity.h | 2 +- esphome/components/datetime/datetime_entity.h | 2 +- esphome/components/datetime/time_entity.h | 2 +- esphome/components/event/event.h | 4 ++-- esphome/components/lock/lock.h | 2 +- esphome/components/number/number.cpp | 6 +++--- esphome/components/select/select.h | 2 +- esphome/components/sensor/sensor.cpp | 4 ++-- esphome/components/switch/switch.cpp | 4 ++-- esphome/components/text/text.h | 2 +- esphome/components/text_sensor/text_sensor.cpp | 4 ++-- esphome/components/valve/valve.h | 2 +- esphome/core/entity_base.cpp | 18 ++++++++++++++++++ esphome/core/entity_base.h | 18 ++++++------------ 17 files changed, 45 insertions(+), 33 deletions(-) diff --git a/esphome/components/binary_sensor/binary_sensor.cpp b/esphome/components/binary_sensor/binary_sensor.cpp index 7c3b06970d..cd9120c848 100644 --- a/esphome/components/binary_sensor/binary_sensor.cpp +++ b/esphome/components/binary_sensor/binary_sensor.cpp @@ -14,7 +14,7 @@ void log_binary_sensor(const char *tag, const char *prefix, const char *type, Bi } ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str()); - LOG_ENTITY_DEVICE_CLASS(tag, prefix, *obj); + LOG_ENTITY_DEVICE_CLASS(prefix, *obj); } void BinarySensor::publish_state(bool new_state) { diff --git a/esphome/components/button/button.cpp b/esphome/components/button/button.cpp index 8c06cfe59b..89a4eda5cd 100644 --- a/esphome/components/button/button.cpp +++ b/esphome/components/button/button.cpp @@ -12,7 +12,7 @@ void log_button(const char *tag, const char *prefix, const char *type, Button *o } ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str()); - LOG_ENTITY_ICON(tag, prefix, *obj); + LOG_ENTITY_ICON(prefix, *obj); } void Button::press() { diff --git a/esphome/components/cover/cover.h b/esphome/components/cover/cover.h index e5427ceaa8..a2a0cc7aa8 100644 --- a/esphome/components/cover/cover.h +++ b/esphome/components/cover/cover.h @@ -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)); \ + LOG_ENTITY_DEVICE_CLASS(prefix, *(obj)); \ } class Cover; diff --git a/esphome/components/datetime/date_entity.h b/esphome/components/datetime/date_entity.h index cbf2b85506..2892c7b920 100644 --- a/esphome/components/datetime/date_entity.h +++ b/esphome/components/datetime/date_entity.h @@ -15,7 +15,7 @@ namespace esphome::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)); \ + LOG_ENTITY_ICON(prefix, *(obj)); \ } class DateCall; diff --git a/esphome/components/datetime/datetime_entity.h b/esphome/components/datetime/datetime_entity.h index b1b8a77846..b3c2563b49 100644 --- a/esphome/components/datetime/datetime_entity.h +++ b/esphome/components/datetime/datetime_entity.h @@ -15,7 +15,7 @@ namespace esphome::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)); \ + LOG_ENTITY_ICON(prefix, *(obj)); \ } class DateTimeCall; diff --git a/esphome/components/datetime/time_entity.h b/esphome/components/datetime/time_entity.h index 3f224684bb..8159c35ee9 100644 --- a/esphome/components/datetime/time_entity.h +++ b/esphome/components/datetime/time_entity.h @@ -15,7 +15,7 @@ namespace esphome::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)); \ + LOG_ENTITY_ICON(prefix, *(obj)); \ } class TimeCall; diff --git a/esphome/components/event/event.h b/esphome/components/event/event.h index a7451407bb..a92b4b79d8 100644 --- a/esphome/components/event/event.h +++ b/esphome/components/event/event.h @@ -16,8 +16,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)); \ + LOG_ENTITY_ICON(prefix, *(obj)); \ + LOG_ENTITY_DEVICE_CLASS(prefix, *(obj)); \ } class Event : public EntityBase, public EntityBase_DeviceClass { diff --git a/esphome/components/lock/lock.h b/esphome/components/lock/lock.h index 69fc405713..55b4e7eebe 100644 --- a/esphome/components/lock/lock.h +++ b/esphome/components/lock/lock.h @@ -14,7 +14,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)); \ + LOG_ENTITY_ICON(prefix, *(obj)); \ if ((obj)->traits.get_assumed_state()) { \ ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \ } \ diff --git a/esphome/components/number/number.cpp b/esphome/components/number/number.cpp index 1c4126496c..7b335f5412 100644 --- a/esphome/components/number/number.cpp +++ b/esphome/components/number/number.cpp @@ -14,9 +14,9 @@ void log_number(const char *tag, const char *prefix, const char *type, Number *o } ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str()); - LOG_ENTITY_ICON(tag, prefix, *obj); - LOG_ENTITY_UNIT_OF_MEASUREMENT(tag, prefix, obj->traits); - LOG_ENTITY_DEVICE_CLASS(tag, prefix, obj->traits); + LOG_ENTITY_ICON(prefix, *obj); + LOG_ENTITY_UNIT_OF_MEASUREMENT(prefix, obj->traits); + LOG_ENTITY_DEVICE_CLASS(prefix, obj->traits); } void Number::publish_state(float state) { diff --git a/esphome/components/select/select.h b/esphome/components/select/select.h index c91acd1e19..4028e4cf72 100644 --- a/esphome/components/select/select.h +++ b/esphome/components/select/select.h @@ -12,7 +12,7 @@ namespace esphome::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)); \ + LOG_ENTITY_ICON(prefix, *(obj)); \ } #define SUB_SELECT(name) \ diff --git a/esphome/components/sensor/sensor.cpp b/esphome/components/sensor/sensor.cpp index 3f2be02af2..d6fc7f3c0a 100644 --- a/esphome/components/sensor/sensor.cpp +++ b/esphome/components/sensor/sensor.cpp @@ -22,8 +22,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); + LOG_ENTITY_DEVICE_CLASS(prefix, *obj); + LOG_ENTITY_ICON(prefix, *obj); if (obj->get_force_update()) { ESP_LOGV(tag, "%s Force Update: YES", prefix); diff --git a/esphome/components/switch/switch.cpp b/esphome/components/switch/switch.cpp index 61a273d25c..e9b27b3682 100644 --- a/esphome/components/switch/switch.cpp +++ b/esphome/components/switch/switch.cpp @@ -96,14 +96,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); + LOG_ENTITY_ICON(prefix, *obj); 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); + LOG_ENTITY_DEVICE_CLASS(prefix, *obj); } } diff --git a/esphome/components/text/text.h b/esphome/components/text/text.h index 3a1bea56cb..c1b6554d51 100644 --- a/esphome/components/text/text.h +++ b/esphome/components/text/text.h @@ -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)); \ + LOG_ENTITY_ICON(prefix, *(obj)); \ } /** Base-class for all text inputs. diff --git a/esphome/components/text_sensor/text_sensor.cpp b/esphome/components/text_sensor/text_sensor.cpp index c48bdf4b82..559685ebe6 100644 --- a/esphome/components/text_sensor/text_sensor.cpp +++ b/esphome/components/text_sensor/text_sensor.cpp @@ -15,8 +15,8 @@ void log_text_sensor(const char *tag, const char *prefix, const char *type, Text } 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); + LOG_ENTITY_DEVICE_CLASS(prefix, *obj); + LOG_ENTITY_ICON(prefix, *obj); } void TextSensor::publish_state(const std::string &state) { this->publish_state(state.data(), state.size()); } diff --git a/esphome/components/valve/valve.h b/esphome/components/valve/valve.h index cd46144372..c887527fb8 100644 --- a/esphome/components/valve/valve.h +++ b/esphome/components/valve/valve.h @@ -20,7 +20,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)); \ + LOG_ENTITY_DEVICE_CLASS(prefix, *(obj)); \ } class Valve; diff --git a/esphome/core/entity_base.cpp b/esphome/core/entity_base.cpp index 7d7878f53a..811b856b5e 100644 --- a/esphome/core/entity_base.cpp +++ b/esphome/core/entity_base.cpp @@ -152,4 +152,22 @@ void EntityBase_UnitOfMeasurement::set_unit_of_measurement(const char *unit_of_m this->unit_of_measurement_ = unit_of_measurement; } +void log_entity_icon(const char *tag, const char *prefix, const EntityBase &obj) { + if (!obj.get_icon_ref().empty()) { + ESP_LOGCONFIG(tag, "%s Icon: '%s'", prefix, obj.get_icon_ref().c_str()); + } +} + +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()); + } +} + +void log_entity_unit_of_measurement(const char *tag, const char *prefix, const EntityBase_UnitOfMeasurement &obj) { + if (!obj.get_unit_of_measurement_ref().empty()) { + ESP_LOGCONFIG(tag, "%s Unit of Measurement: '%s'", prefix, obj.get_unit_of_measurement_ref().c_str()); + } +} + } // namespace esphome diff --git a/esphome/core/entity_base.h b/esphome/core/entity_base.h index 6d90a37401..b37b7b0d0e 100644 --- a/esphome/core/entity_base.h +++ b/esphome/core/entity_base.h @@ -231,20 +231,14 @@ class EntityBase_UnitOfMeasurement { // NOLINT(readability-identifier-naming) }; /// Log entity icon if set (for use in dump_config) -#define LOG_ENTITY_ICON(tag, prefix, obj) \ - if (!(obj).get_icon_ref().empty()) { \ - ESP_LOGCONFIG(tag, "%s Icon: '%s'", prefix, (obj).get_icon_ref().c_str()); \ - } +#define LOG_ENTITY_ICON(prefix, obj) log_entity_icon(TAG, prefix, obj) +void log_entity_icon(const char *tag, const char *prefix, const EntityBase &obj); /// Log entity device class if set (for use in dump_config) -#define LOG_ENTITY_DEVICE_CLASS(tag, prefix, obj) \ - if (!(obj).get_device_class_ref().empty()) { \ - ESP_LOGCONFIG(tag, "%s Device Class: '%s'", prefix, (obj).get_device_class_ref().c_str()); \ - } +#define LOG_ENTITY_DEVICE_CLASS(prefix, obj) log_entity_device_class(TAG, prefix, obj) +void log_entity_device_class(const char *tag, const char *prefix, const EntityBase_DeviceClass &obj); /// Log entity unit of measurement if set (for use in dump_config) -#define LOG_ENTITY_UNIT_OF_MEASUREMENT(tag, prefix, obj) \ - if (!(obj).get_unit_of_measurement_ref().empty()) { \ - ESP_LOGCONFIG(tag, "%s Unit of Measurement: '%s'", prefix, (obj).get_unit_of_measurement_ref().c_str()); \ - } +#define LOG_ENTITY_UNIT_OF_MEASUREMENT(prefix, obj) log_entity_unit_of_measurement(TAG, prefix, obj) +void log_entity_unit_of_measurement(const char *tag, const char *prefix, const EntityBase_UnitOfMeasurement &obj); /** * An entity that has a state.