This commit is contained in:
J. Nick Koston
2026-01-27 17:29:02 -10:00
parent cd80ceacfc
commit 3d789f9ccc
17 changed files with 45 additions and 33 deletions

View File

@@ -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) {

View File

@@ -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() {

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)); \
LOG_ENTITY_DEVICE_CLASS(prefix, *(obj)); \
}
class Cover;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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); \
} \

View File

@@ -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) {

View File

@@ -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) \

View File

@@ -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);

View File

@@ -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);
}
}

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)); \
LOG_ENTITY_ICON(prefix, *(obj)); \
}
/** Base-class for all text inputs.

View File

@@ -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()); }

View File

@@ -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;

View File

@@ -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

View File

@@ -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.