mirror of
https://github.com/esphome/esphome.git
synced 2025-10-28 13:43:54 +00:00
Reduce ESP_LOGCONFIG calls (#9026)
This commit is contained in:
@@ -65,7 +65,24 @@ bool Switch::is_inverted() const { return this->inverted_; }
|
||||
|
||||
void log_switch(const char *tag, const char *prefix, const char *type, Switch *obj) {
|
||||
if (obj != nullptr) {
|
||||
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
|
||||
// Prepare restore mode string
|
||||
const LogString *onoff = LOG_STR(""), *inverted = onoff, *restore;
|
||||
if (obj->restore_mode & RESTORE_MODE_DISABLED_MASK) {
|
||||
restore = LOG_STR("disabled");
|
||||
} else {
|
||||
onoff = obj->restore_mode & RESTORE_MODE_ON_MASK ? LOG_STR("ON") : LOG_STR("OFF");
|
||||
inverted = obj->restore_mode & RESTORE_MODE_INVERTED_MASK ? LOG_STR("inverted ") : LOG_STR("");
|
||||
restore = obj->restore_mode & RESTORE_MODE_PERSISTENT_MASK ? LOG_STR("restore defaults to") : LOG_STR("always");
|
||||
}
|
||||
|
||||
// Build the base message with mandatory fields
|
||||
ESP_LOGCONFIG(tag,
|
||||
"%s%s '%s'\n"
|
||||
"%s Restore Mode: %s%s %s",
|
||||
prefix, type, obj->get_name().c_str(), prefix, LOG_STR_ARG(inverted), LOG_STR_ARG(restore),
|
||||
LOG_STR_ARG(onoff));
|
||||
|
||||
// Add optional fields separately
|
||||
if (!obj->get_icon().empty()) {
|
||||
ESP_LOGCONFIG(tag, "%s Icon: '%s'", prefix, obj->get_icon().c_str());
|
||||
}
|
||||
@@ -78,17 +95,6 @@ void log_switch(const char *tag, const char *prefix, const char *type, Switch *o
|
||||
if (!obj->get_device_class().empty()) {
|
||||
ESP_LOGCONFIG(tag, "%s Device Class: '%s'", prefix, obj->get_device_class().c_str());
|
||||
}
|
||||
const LogString *onoff = LOG_STR(""), *inverted = onoff, *restore;
|
||||
if (obj->restore_mode & RESTORE_MODE_DISABLED_MASK) {
|
||||
restore = LOG_STR("disabled");
|
||||
} else {
|
||||
onoff = obj->restore_mode & RESTORE_MODE_ON_MASK ? LOG_STR("ON") : LOG_STR("OFF");
|
||||
inverted = obj->restore_mode & RESTORE_MODE_INVERTED_MASK ? LOG_STR("inverted ") : LOG_STR("");
|
||||
restore = obj->restore_mode & RESTORE_MODE_PERSISTENT_MASK ? LOG_STR("restore defaults to") : LOG_STR("always");
|
||||
}
|
||||
|
||||
ESP_LOGCONFIG(tag, "%s Restore Mode: %s%s %s", prefix, LOG_STR_ARG(inverted), LOG_STR_ARG(restore),
|
||||
LOG_STR_ARG(onoff));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user