From 6e4e5ae830d0e725d8a78007699c5f0e66e8d7bd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 20 Oct 2026 15:30:18 -1000 Subject: [PATCH] [mqtt] Print the dump_config header in LOG_MQTT_COMPONENT (#21226) --- esphome/components/mqtt/mqtt_alarm_control_panel.cpp | 1 - esphome/components/mqtt/mqtt_binary_sensor.cpp | 5 +---- esphome/components/mqtt/mqtt_button.cpp | 5 +---- esphome/components/mqtt/mqtt_component.cpp | 1 + esphome/components/mqtt/mqtt_cover.cpp | 1 - esphome/components/mqtt/mqtt_date.cpp | 5 +---- esphome/components/mqtt/mqtt_datetime.cpp | 5 +---- esphome/components/mqtt/mqtt_event.cpp | 9 ++++----- esphome/components/mqtt/mqtt_fan.cpp | 1 - esphome/components/mqtt/mqtt_light.cpp | 5 +---- esphome/components/mqtt/mqtt_lock.cpp | 5 +---- esphome/components/mqtt/mqtt_number.cpp | 5 +---- esphome/components/mqtt/mqtt_select.cpp | 5 +---- esphome/components/mqtt/mqtt_sensor.cpp | 3 +-- esphome/components/mqtt/mqtt_switch.cpp | 5 +---- esphome/components/mqtt/mqtt_text.cpp | 5 +---- esphome/components/mqtt/mqtt_text_sensor.cpp | 5 +---- esphome/components/mqtt/mqtt_time.cpp | 5 +---- esphome/components/mqtt/mqtt_update.cpp | 5 +---- esphome/components/mqtt/mqtt_valve.cpp | 1 - 20 files changed, 19 insertions(+), 63 deletions(-) diff --git a/esphome/components/mqtt/mqtt_alarm_control_panel.cpp b/esphome/components/mqtt/mqtt_alarm_control_panel.cpp index 225f8396339..ef18c0319a6 100644 --- a/esphome/components/mqtt/mqtt_alarm_control_panel.cpp +++ b/esphome/components/mqtt/mqtt_alarm_control_panel.cpp @@ -77,7 +77,6 @@ void MQTTAlarmControlPanelComponent::setup() { } void MQTTAlarmControlPanelComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT alarm_control_panel '%s':", this->alarm_control_panel_->get_name().c_str()); LOG_MQTT_COMPONENT(true, true); ESP_LOGCONFIG(TAG, " Supported Features: %" PRIu32 "\n" diff --git a/esphome/components/mqtt/mqtt_binary_sensor.cpp b/esphome/components/mqtt/mqtt_binary_sensor.cpp index 7a75cca6e88..f408119bb9e 100644 --- a/esphome/components/mqtt/mqtt_binary_sensor.cpp +++ b/esphome/components/mqtt/mqtt_binary_sensor.cpp @@ -17,10 +17,7 @@ void MQTTBinarySensorComponent::setup() { this->binary_sensor_->add_on_state_callback([this](bool state) { this->publish_state(state); }); } -void MQTTBinarySensorComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Binary Sensor '%s':", this->binary_sensor_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, false); -} +void MQTTBinarySensorComponent::dump_config() { LOG_MQTT_COMPONENT(true, false); } MQTTBinarySensorComponent::MQTTBinarySensorComponent(binary_sensor::BinarySensor *binary_sensor) : binary_sensor_(binary_sensor) { if (this->binary_sensor_->is_status_binary_sensor()) { diff --git a/esphome/components/mqtt/mqtt_button.cpp b/esphome/components/mqtt/mqtt_button.cpp index a04121e2a13..df2163ca2f1 100644 --- a/esphome/components/mqtt/mqtt_button.cpp +++ b/esphome/components/mqtt/mqtt_button.cpp @@ -24,10 +24,7 @@ void MQTTButtonComponent::setup() { } }); } -void MQTTButtonComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Button '%s': ", this->button_->get_name().c_str()); - LOG_MQTT_COMPONENT(false, true); -} +void MQTTButtonComponent::dump_config() { LOG_MQTT_COMPONENT(false, true); } void MQTTButtonComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) { config.state_topic = false; diff --git a/esphome/components/mqtt/mqtt_component.cpp b/esphome/components/mqtt/mqtt_component.cpp index 7e4b8be725d..f4391790c8a 100644 --- a/esphome/components/mqtt/mqtt_component.cpp +++ b/esphome/components/mqtt/mqtt_component.cpp @@ -38,6 +38,7 @@ inline char *append_char(char *p, char c) { // Function implementation of LOG_MQTT_COMPONENT macro to reduce code size void log_mqtt_component(const char *tag, MQTTComponent *obj, bool state_topic, bool command_topic) { + ESP_LOGCONFIG(tag, "MQTT %s '%s':", obj->component_type(), obj->friendly_name_().c_str()); char buf[MQTT_DEFAULT_TOPIC_MAX_LEN]; if (state_topic) { ESP_LOGCONFIG(tag, " State Topic: '%s'", obj->get_state_topic_to_(buf).c_str()); diff --git a/esphome/components/mqtt/mqtt_cover.cpp b/esphome/components/mqtt/mqtt_cover.cpp index a7da9a1b228..f279403de13 100644 --- a/esphome/components/mqtt/mqtt_cover.cpp +++ b/esphome/components/mqtt/mqtt_cover.cpp @@ -63,7 +63,6 @@ void MQTTCoverComponent::setup() { } void MQTTCoverComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT cover '%s':", this->cover_->get_name().c_str()); auto traits = this->cover_->get_traits(); bool has_command_topic = traits.get_supports_position() || !traits.get_supports_tilt(); LOG_MQTT_COMPONENT(true, has_command_topic); diff --git a/esphome/components/mqtt/mqtt_date.cpp b/esphome/components/mqtt/mqtt_date.cpp index b5f1cf8fb8b..b580ad5eddd 100644 --- a/esphome/components/mqtt/mqtt_date.cpp +++ b/esphome/components/mqtt/mqtt_date.cpp @@ -34,10 +34,7 @@ void MQTTDateComponent::setup() { [this]() { this->publish_state(this->date_->year, this->date_->month, this->date_->day); }); } -void MQTTDateComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Date '%s':", this->date_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, true); -} +void MQTTDateComponent::dump_config() { LOG_MQTT_COMPONENT(true, true); } MQTT_COMPONENT_TYPE(MQTTDateComponent, "date") const EntityBase *MQTTDateComponent::get_entity() const { return this->date_; } diff --git a/esphome/components/mqtt/mqtt_datetime.cpp b/esphome/components/mqtt/mqtt_datetime.cpp index 82755809387..e0129cef0f9 100644 --- a/esphome/components/mqtt/mqtt_datetime.cpp +++ b/esphome/components/mqtt/mqtt_datetime.cpp @@ -45,10 +45,7 @@ void MQTTDateTimeComponent::setup() { }); } -void MQTTDateTimeComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT DateTime '%s':", this->datetime_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, true); -} +void MQTTDateTimeComponent::dump_config() { LOG_MQTT_COMPONENT(true, true); } MQTT_COMPONENT_TYPE(MQTTDateTimeComponent, "datetime") const EntityBase *MQTTDateTimeComponent::get_entity() const { return this->datetime_; } diff --git a/esphome/components/mqtt/mqtt_event.cpp b/esphome/components/mqtt/mqtt_event.cpp index 4266722ca82..7bf213e80bd 100644 --- a/esphome/components/mqtt/mqtt_event.cpp +++ b/esphome/components/mqtt/mqtt_event.cpp @@ -28,12 +28,11 @@ void MQTTEventComponent::setup() { } void MQTTEventComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Event '%s': ", this->event_->get_name().c_str()); - ESP_LOGCONFIG(TAG, "Event Types: "); - for (const char *event_type : this->event_->get_event_types()) { - ESP_LOGCONFIG(TAG, "- %s", event_type); - } LOG_MQTT_COMPONENT(true, true); + ESP_LOGCONFIG(TAG, " Event Types:"); + for (const char *event_type : this->event_->get_event_types()) { + ESP_LOGCONFIG(TAG, " - %s", event_type); + } } bool MQTTEventComponent::publish_event_(const std::string &event_type) { diff --git a/esphome/components/mqtt/mqtt_fan.cpp b/esphome/components/mqtt/mqtt_fan.cpp index 7aa2f8e9d5a..8702c962d78 100644 --- a/esphome/components/mqtt/mqtt_fan.cpp +++ b/esphome/components/mqtt/mqtt_fan.cpp @@ -125,7 +125,6 @@ void MQTTFanComponent::setup() { } void MQTTFanComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Fan '%s': ", this->state_->get_name().c_str()); LOG_MQTT_COMPONENT(true, true); if (this->state_->get_traits().supports_direction()) { ESP_LOGCONFIG(TAG, diff --git a/esphome/components/mqtt/mqtt_light.cpp b/esphome/components/mqtt/mqtt_light.cpp index e1affae8a24..7a9240f73e6 100644 --- a/esphome/components/mqtt/mqtt_light.cpp +++ b/esphome/components/mqtt/mqtt_light.cpp @@ -87,10 +87,7 @@ void MQTTJSONLightComponent::send_discovery(JsonObject root, mqtt::SendDiscovery } } bool MQTTJSONLightComponent::send_initial_state() { return this->publish_state_(); } -void MQTTJSONLightComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Light '%s':", this->state_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, true); -} +void MQTTJSONLightComponent::dump_config() { LOG_MQTT_COMPONENT(true, true); } } // namespace esphome::mqtt diff --git a/esphome/components/mqtt/mqtt_lock.cpp b/esphome/components/mqtt/mqtt_lock.cpp index 8e9a6289852..2263856f43d 100644 --- a/esphome/components/mqtt/mqtt_lock.cpp +++ b/esphome/components/mqtt/mqtt_lock.cpp @@ -31,10 +31,7 @@ void MQTTLockComponent::setup() { this->lock_->add_on_state_callback( [this](LockState /*state*/) { this->defer(SEND_DEFER_ID, [this]() { this->publish_state(); }); }); } -void MQTTLockComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Lock '%s': ", this->lock_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, true); -} +void MQTTLockComponent::dump_config() { LOG_MQTT_COMPONENT(true, true); } MQTT_COMPONENT_TYPE(MQTTLockComponent, "lock") const EntityBase *MQTTLockComponent::get_entity() const { return this->lock_; } diff --git a/esphome/components/mqtt/mqtt_number.cpp b/esphome/components/mqtt/mqtt_number.cpp index 3b2bebf291d..58492e2605d 100644 --- a/esphome/components/mqtt/mqtt_number.cpp +++ b/esphome/components/mqtt/mqtt_number.cpp @@ -32,10 +32,7 @@ void MQTTNumberComponent::setup() { this->number_->add_on_state_callback([this](float state) { this->publish_state(state); }); } -void MQTTNumberComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Number '%s':", this->number_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, false); -} +void MQTTNumberComponent::dump_config() { LOG_MQTT_COMPONENT(true, false); } MQTT_COMPONENT_TYPE(MQTTNumberComponent, "number") const EntityBase *MQTTNumberComponent::get_entity() const { return this->number_; } diff --git a/esphome/components/mqtt/mqtt_select.cpp b/esphome/components/mqtt/mqtt_select.cpp index 42c0ae002e4..c24ddb80ea7 100644 --- a/esphome/components/mqtt/mqtt_select.cpp +++ b/esphome/components/mqtt/mqtt_select.cpp @@ -23,10 +23,7 @@ void MQTTSelectComponent::setup() { this->select_->add_on_state_callback([this](size_t index) { this->publish_state(this->select_->option_at(index)); }); } -void MQTTSelectComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Select '%s':", this->select_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, false); -} +void MQTTSelectComponent::dump_config() { LOG_MQTT_COMPONENT(true, false); } MQTT_COMPONENT_TYPE(MQTTSelectComponent, "select") const EntityBase *MQTTSelectComponent::get_entity() const { return this->select_; } diff --git a/esphome/components/mqtt/mqtt_sensor.cpp b/esphome/components/mqtt/mqtt_sensor.cpp index bdaaa47e8f4..a3f7a0cf537 100644 --- a/esphome/components/mqtt/mqtt_sensor.cpp +++ b/esphome/components/mqtt/mqtt_sensor.cpp @@ -25,11 +25,10 @@ void MQTTSensorComponent::setup() { } void MQTTSensorComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Sensor '%s':", this->sensor_->get_name().c_str()); + LOG_MQTT_COMPONENT(true, false); if (this->get_expire_after() > 0) { ESP_LOGCONFIG(TAG, " Expire After: %" PRIu32 "s", this->get_expire_after() / 1000); } - LOG_MQTT_COMPONENT(true, false); } MQTT_COMPONENT_TYPE(MQTTSensorComponent, "sensor") diff --git a/esphome/components/mqtt/mqtt_switch.cpp b/esphome/components/mqtt/mqtt_switch.cpp index 44ce2497720..77ec004cb98 100644 --- a/esphome/components/mqtt/mqtt_switch.cpp +++ b/esphome/components/mqtt/mqtt_switch.cpp @@ -36,10 +36,7 @@ void MQTTSwitchComponent::setup() { this->switch_->add_on_state_callback( [this](bool enabled) { this->defer(SEND_DEFER_ID, [this, enabled]() { this->publish_state(enabled); }); }); } -void MQTTSwitchComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Switch '%s': ", this->switch_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, true); -} +void MQTTSwitchComponent::dump_config() { LOG_MQTT_COMPONENT(true, true); } MQTT_COMPONENT_TYPE(MQTTSwitchComponent, "switch") const EntityBase *MQTTSwitchComponent::get_entity() const { return this->switch_; } diff --git a/esphome/components/mqtt/mqtt_text.cpp b/esphome/components/mqtt/mqtt_text.cpp index dd43a8e2cb3..979b50e0a2e 100644 --- a/esphome/components/mqtt/mqtt_text.cpp +++ b/esphome/components/mqtt/mqtt_text.cpp @@ -28,10 +28,7 @@ void MQTTTextComponent::setup() { this->text_->add_on_state_callback([this](const std::string &state) { this->publish_state(state); }); } -void MQTTTextComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT text '%s':", this->text_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, true); -} +void MQTTTextComponent::dump_config() { LOG_MQTT_COMPONENT(true, true); } MQTT_COMPONENT_TYPE(MQTTTextComponent, "text") const EntityBase *MQTTTextComponent::get_entity() const { return this->text_; } diff --git a/esphome/components/mqtt/mqtt_text_sensor.cpp b/esphome/components/mqtt/mqtt_text_sensor.cpp index d105aaac992..6fbe8297059 100644 --- a/esphome/components/mqtt/mqtt_text_sensor.cpp +++ b/esphome/components/mqtt/mqtt_text_sensor.cpp @@ -20,10 +20,7 @@ void MQTTTextSensor::setup() { this->sensor_->add_on_state_callback([this](const std::string &state) { this->publish_state(state); }); } -void MQTTTextSensor::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Text Sensor '%s':", this->sensor_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, false); -} +void MQTTTextSensor::dump_config() { LOG_MQTT_COMPONENT(true, false); } bool MQTTTextSensor::publish_state(const std::string &value) { char topic_buf[MQTT_DEFAULT_TOPIC_MAX_LEN]; diff --git a/esphome/components/mqtt/mqtt_time.cpp b/esphome/components/mqtt/mqtt_time.cpp index 889ee2bf349..70ea89a7ba0 100644 --- a/esphome/components/mqtt/mqtt_time.cpp +++ b/esphome/components/mqtt/mqtt_time.cpp @@ -34,10 +34,7 @@ void MQTTTimeComponent::setup() { [this]() { this->publish_state(this->time_->hour, this->time_->minute, this->time_->second); }); } -void MQTTTimeComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Time '%s':", this->time_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, true); -} +void MQTTTimeComponent::dump_config() { LOG_MQTT_COMPONENT(true, true); } MQTT_COMPONENT_TYPE(MQTTTimeComponent, "time") const EntityBase *MQTTTimeComponent::get_entity() const { return this->time_; } diff --git a/esphome/components/mqtt/mqtt_update.cpp b/esphome/components/mqtt/mqtt_update.cpp index 69b2f64771b..7cdc0b4fc12 100644 --- a/esphome/components/mqtt/mqtt_update.cpp +++ b/esphome/components/mqtt/mqtt_update.cpp @@ -48,10 +48,7 @@ void MQTTUpdateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCon bool MQTTUpdateComponent::send_initial_state() { return this->publish_state(); } -void MQTTUpdateComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT Update '%s': ", this->update_->get_name().c_str()); - LOG_MQTT_COMPONENT(true, true); -} +void MQTTUpdateComponent::dump_config() { LOG_MQTT_COMPONENT(true, true); } MQTT_COMPONENT_TYPE(MQTTUpdateComponent, "update") const EntityBase *MQTTUpdateComponent::get_entity() const { return this->update_; } diff --git a/esphome/components/mqtt/mqtt_valve.cpp b/esphome/components/mqtt/mqtt_valve.cpp index b41a482de94..9ee1ce85dac 100644 --- a/esphome/components/mqtt/mqtt_valve.cpp +++ b/esphome/components/mqtt/mqtt_valve.cpp @@ -51,7 +51,6 @@ void MQTTValveComponent::setup() { } void MQTTValveComponent::dump_config() { - ESP_LOGCONFIG(TAG, "MQTT valve '%s':", this->valve_->get_name().c_str()); auto traits = this->valve_->get_traits(); bool has_command_topic = traits.get_supports_position(); LOG_MQTT_COMPONENT(true, has_command_topic);