From 39d63a316693816baece3ffbbf6758ba58f3aea6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 12 Oct 2026 17:10:33 -1000 Subject: [PATCH] Keep the entity domain log and dump helpers on the flash-safe name accessors --- .../alarm_control_panel.cpp | 2 +- .../binary_sensor/binary_sensor.cpp | 4 +-- esphome/components/button/button.cpp | 4 +-- esphome/components/climate/climate.cpp | 17 +++++++----- esphome/components/climate/climate.h | 2 +- esphome/components/cover/cover.cpp | 8 +++--- esphome/components/cover/cover.h | 2 +- esphome/components/datetime/date_entity.cpp | 4 +-- esphome/components/datetime/date_entity.h | 2 +- .../components/datetime/datetime_entity.cpp | 4 +-- esphome/components/datetime/datetime_entity.h | 2 +- esphome/components/datetime/time_entity.cpp | 4 +-- esphome/components/datetime/time_entity.h | 2 +- esphome/components/event/event.cpp | 4 +-- esphome/components/event/event.h | 2 +- esphome/components/fan/fan.cpp | 13 +++++----- esphome/components/fan/fan.h | 2 +- esphome/components/infrared/infrared.cpp | 2 +- .../components/light/addressable_light.cpp | 2 +- esphome/components/light/light_call.cpp | 16 ++++++------ esphome/components/light/light_state.cpp | 2 +- esphome/components/lock/lock.cpp | 10 +++---- esphome/components/lock/lock.h | 2 +- .../components/media_player/media_player.cpp | 4 +-- esphome/components/number/number.cpp | 4 +-- esphome/components/number/number_call.cpp | 6 ++--- .../radio_frequency/radio_frequency.cpp | 2 +- esphome/components/select/select.cpp | 6 ++--- esphome/components/select/select.h | 2 +- esphome/components/select/select_call.cpp | 4 +-- esphome/components/sensor/sensor.cpp | 8 +++--- esphome/components/switch/switch.cpp | 10 +++---- esphome/components/text/text.cpp | 4 +-- esphome/components/text/text.h | 2 +- esphome/components/text/text_call.cpp | 8 +++--- .../components/text_sensor/text_sensor.cpp | 8 +++--- esphome/components/update/update_entity.cpp | 2 +- esphome/components/valve/valve.cpp | 14 +++++----- esphome/components/valve/valve.h | 2 +- .../components/water_heater/water_heater.cpp | 26 ++++++++++--------- 40 files changed, 116 insertions(+), 108 deletions(-) diff --git a/esphome/components/alarm_control_panel/alarm_control_panel.cpp b/esphome/components/alarm_control_panel/alarm_control_panel.cpp index 6f23b1aca8..730cb80fd1 100644 --- a/esphome/components/alarm_control_panel/alarm_control_panel.cpp +++ b/esphome/components/alarm_control_panel/alarm_control_panel.cpp @@ -31,7 +31,7 @@ void AlarmControlPanel::publish_state(AlarmControlPanelState state) { this->last_update_ = millis(); if (state != this->current_state_) { auto prev_state = this->current_state_; - ESP_LOGV(TAG, "'%s' >> %s (was %s)", this->get_name().c_str(), + ESP_LOGV(TAG, "'%s' >> %s (was %s)", LOG_STR_ARG(this->get_log_name()), LOG_STR_ARG(alarm_control_panel_state_to_string(state)), LOG_STR_ARG(alarm_control_panel_state_to_string(prev_state))); this->current_state_ = state; diff --git a/esphome/components/binary_sensor/binary_sensor.cpp b/esphome/components/binary_sensor/binary_sensor.cpp index 43915c4e17..b4da1a15b6 100644 --- a/esphome/components/binary_sensor/binary_sensor.cpp +++ b/esphome/components/binary_sensor/binary_sensor.cpp @@ -13,7 +13,7 @@ void log_binary_sensor(const char *tag, const char *prefix, const char *type, Bi return; } - ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str()); + ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, LOG_STR_ARG(obj->get_log_name())); LOG_ENTITY_DEVICE_CLASS(tag, prefix, *obj); } @@ -38,7 +38,7 @@ bool BinarySensor::set_new_state(const optional &new_state) { #if defined(USE_BINARY_SENSOR) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_binary_sensor_update(this); #endif - ESP_LOGV(TAG, "'%s' >> %s", this->get_name().c_str(), ONOFFMAYBE(new_state)); + ESP_LOGV(TAG, "'%s' >> %s", LOG_STR_ARG(this->get_log_name()), ONOFFMAYBE(new_state)); return true; } return false; diff --git a/esphome/components/button/button.cpp b/esphome/components/button/button.cpp index e85ce60df6..157693fffe 100644 --- a/esphome/components/button/button.cpp +++ b/esphome/components/button/button.cpp @@ -11,12 +11,12 @@ void log_button(const char *tag, const char *prefix, const char *type, Button *o return; } - ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str()); + ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, LOG_STR_ARG(obj->get_log_name())); LOG_ENTITY_ICON(tag, prefix, *obj); } void Button::press() { - ESP_LOGV(TAG, "'%s' Pressed.", this->get_name().c_str()); + ESP_LOGV(TAG, "'%s' Pressed.", LOG_STR_ARG(this->get_log_name())); this->press_action(); this->press_callback_.call(); } diff --git a/esphome/components/climate/climate.cpp b/esphome/components/climate/climate.cpp index 790307cec1..0403b5ad01 100644 --- a/esphome/components/climate/climate.cpp +++ b/esphome/components/climate/climate.cpp @@ -46,7 +46,7 @@ constexpr StringToUint8 CLIMATE_SWING_MODES_BY_STR[] = { void ClimateCall::perform() { this->parent_->control_callback_.call(*this); - ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name())); this->validate_(); if (this->mode_.has_value()) { const LogString *mode_s = climate_mode_to_string(*this->mode_); @@ -183,7 +183,7 @@ ClimateCall &ClimateCall::set_mode(const char *mode, size_t len) { return *this; } } - ESP_LOGW(TAG, "'%s' - Unrecognized mode %.*s", this->parent_->get_name().c_str(), (int) len, mode); + ESP_LOGW(TAG, "'%s' - Unrecognized mode %.*s", LOG_STR_ARG(this->parent_->get_log_name()), (int) len, mode); return *this; } @@ -214,7 +214,8 @@ ClimateCall &ClimateCall::set_fan_mode(const char *custom_fan_mode, size_t len) this->fan_mode_.reset(); return *this; } - ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %.*s", this->parent_->get_name().c_str(), (int) len, custom_fan_mode); + ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %.*s", LOG_STR_ARG(this->parent_->get_log_name()), (int) len, + custom_fan_mode); return *this; } @@ -252,7 +253,8 @@ ClimateCall &ClimateCall::set_preset(const char *custom_preset, size_t len) { this->preset_.reset(); return *this; } - ESP_LOGW(TAG, "'%s' - Unrecognized preset %.*s", this->parent_->get_name().c_str(), (int) len, custom_preset); + ESP_LOGW(TAG, "'%s' - Unrecognized preset %.*s", LOG_STR_ARG(this->parent_->get_log_name()), (int) len, + custom_preset); return *this; } @@ -280,7 +282,8 @@ ClimateCall &ClimateCall::set_swing_mode(const char *swing_mode, size_t len) { return *this; } } - ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %.*s", this->parent_->get_name().c_str(), (int) len, swing_mode); + ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %.*s", LOG_STR_ARG(this->parent_->get_log_name()), (int) len, + swing_mode); return *this; } @@ -428,7 +431,7 @@ void Climate::save_state_(const ClimateTraits &traits) { void Climate::publish_state() { this->set_has_state(true); - ESP_LOGV(TAG, "'%s' >>", this->name_.c_str()); + ESP_LOGV(TAG, "'%s' >>", LOG_STR_ARG(this->get_log_name())); auto traits = this->get_traits(); ESP_LOGV(TAG, " Mode: %s", LOG_STR_ARG(climate_mode_to_string(this->mode))); @@ -549,7 +552,7 @@ void ClimateDeviceRestoreState::apply(Climate *climate) { if (traits.supports_mode(this->mode)) { climate->mode = this->mode; } else { - ESP_LOGW(TAG, "'%s' - Saved mode %s is no longer supported, keeping %s", climate->get_name().c_str(), + ESP_LOGW(TAG, "'%s' - Saved mode %s is no longer supported, keeping %s", LOG_STR_ARG(climate->get_log_name()), LOG_STR_ARG(climate_mode_to_string(this->mode)), LOG_STR_ARG(climate_mode_to_string(climate->mode))); } if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE | diff --git a/esphome/components/climate/climate.h b/esphome/components/climate/climate.h index a906897235..c6146f96ae 100644 --- a/esphome/components/climate/climate.h +++ b/esphome/components/climate/climate.h @@ -14,7 +14,7 @@ namespace esphome::climate { #define LOG_CLIMATE(prefix, type, obj) \ if ((obj) != nullptr) { \ - ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ } class Climate; diff --git a/esphome/components/cover/cover.cpp b/esphome/components/cover/cover.cpp index 30e7f70b02..e71dd1c89f 100644 --- a/esphome/components/cover/cover.cpp +++ b/esphome/components/cover/cover.cpp @@ -39,7 +39,7 @@ CoverCall &CoverCall::set_command(const char *command) { } else if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR("TOGGLE")) == 0) { this->set_command_toggle(); } else { - ESP_LOGW(TAG, "'%s' - Unrecognized command %s", this->parent_->get_name().c_str(), command); + ESP_LOGW(TAG, "'%s' - Unrecognized command %s", LOG_STR_ARG(this->parent_->get_log_name()), command); } return *this; } @@ -68,7 +68,7 @@ CoverCall &CoverCall::set_tilt(float tilt) { return *this; } void CoverCall::perform() { - ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name())); auto traits = this->parent_->get_traits(); this->validate_(); if (this->stop_) { @@ -94,7 +94,7 @@ const optional &CoverCall::get_tilt() const { return this->tilt_; } const optional &CoverCall::get_toggle() const { return this->toggle_; } void CoverCall::validate_() { auto traits = this->parent_->get_traits(); - const char *name = this->parent_->get_name().c_str(); + const char *name = LOG_STR_ARG(this->parent_->get_log_name()); if (this->position_.has_value()) { auto pos = *this->position_; @@ -139,7 +139,7 @@ void Cover::publish_state(bool save) { this->position = clamp(this->position, 0.0f, 1.0f); this->tilt = clamp(this->tilt, 0.0f, 1.0f); - ESP_LOGV(TAG, "'%s' >>", this->name_.c_str()); + ESP_LOGV(TAG, "'%s' >>", LOG_STR_ARG(this->get_log_name())); auto traits = this->get_traits(); if (traits.get_supports_position()) { ESP_LOGV(TAG, " Position: %.0f%%", this->position * 100.0f); diff --git a/esphome/components/cover/cover.h b/esphome/components/cover/cover.h index 8bf45cfb57..d7f6df16d9 100644 --- a/esphome/components/cover/cover.h +++ b/esphome/components/cover/cover.h @@ -15,7 +15,7 @@ static constexpr float COVER_CLOSED = 0.0f; #define LOG_COVER(prefix, type, obj) \ if ((obj) != nullptr) { \ - ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ auto traits_ = (obj)->get_traits(); \ if (traits_.get_is_assumed_state()) { \ ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \ diff --git a/esphome/components/datetime/date_entity.cpp b/esphome/components/datetime/date_entity.cpp index 795d54afd9..91b7303d6c 100644 --- a/esphome/components/datetime/date_entity.cpp +++ b/esphome/components/datetime/date_entity.cpp @@ -30,7 +30,7 @@ void DateEntity::publish_state() { return; } this->set_has_state(true); - ESP_LOGV(TAG, "'%s' >> %d-%d-%d", this->get_name().c_str(), this->year_, this->month_, this->day_); + ESP_LOGV(TAG, "'%s' >> %d-%d-%d", LOG_STR_ARG(this->get_log_name()), this->year_, this->month_, this->day_); this->state_callback_.call(); #if defined(USE_DATETIME_DATE) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_date_update(this); @@ -81,7 +81,7 @@ void DateCall::validate_() { void DateCall::perform() { this->validate_(); - ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name())); if (this->year_.has_value()) { ESP_LOGV(TAG, " Year: %d", *this->year_); diff --git a/esphome/components/datetime/date_entity.h b/esphome/components/datetime/date_entity.h index 9404d21512..83ef76ce27 100644 --- a/esphome/components/datetime/date_entity.h +++ b/esphome/components/datetime/date_entity.h @@ -14,7 +14,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()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ LOG_ENTITY_ICON(TAG, prefix, *(obj)); \ } diff --git a/esphome/components/datetime/datetime_entity.cpp b/esphome/components/datetime/datetime_entity.cpp index 6aa1416343..b3bb7c12ea 100644 --- a/esphome/components/datetime/datetime_entity.cpp +++ b/esphome/components/datetime/datetime_entity.cpp @@ -45,7 +45,7 @@ void DateTimeEntity::publish_state() { return; } this->set_has_state(true); - ESP_LOGV(TAG, "'%s' >> %04u-%02u-%02u %02d:%02d:%02d", this->get_name().c_str(), this->year_, this->month_, + ESP_LOGV(TAG, "'%s' >> %04u-%02u-%02u %02d:%02d:%02d", LOG_STR_ARG(this->get_log_name()), this->year_, this->month_, this->day_, this->hour_, this->minute_, this->second_); this->state_callback_.call(); #if defined(USE_DATETIME_DATETIME) && defined(USE_CONTROLLER_REGISTRY) @@ -125,7 +125,7 @@ void DateTimeCall::validate_() { void DateTimeCall::perform() { this->validate_(); - ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name())); if (this->year_.has_value()) { ESP_LOGV(TAG, " Year: %d", *this->year_); diff --git a/esphome/components/datetime/datetime_entity.h b/esphome/components/datetime/datetime_entity.h index 57d305cb52..75a677d67b 100644 --- a/esphome/components/datetime/datetime_entity.h +++ b/esphome/components/datetime/datetime_entity.h @@ -14,7 +14,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()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ LOG_ENTITY_ICON(TAG, prefix, *(obj)); \ } diff --git a/esphome/components/datetime/time_entity.cpp b/esphome/components/datetime/time_entity.cpp index ea1a97256c..8dcbe0ee1c 100644 --- a/esphome/components/datetime/time_entity.cpp +++ b/esphome/components/datetime/time_entity.cpp @@ -26,7 +26,7 @@ void TimeEntity::publish_state() { return; } this->set_has_state(true); - ESP_LOGV(TAG, "'%s' >> %02d:%02d:%02d", this->get_name().c_str(), this->hour_, this->minute_, this->second_); + ESP_LOGV(TAG, "'%s' >> %02d:%02d:%02d", LOG_STR_ARG(this->get_log_name()), this->hour_, this->minute_, this->second_); this->state_callback_.call(); #if defined(USE_DATETIME_TIME) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_time_update(this); @@ -50,7 +50,7 @@ void TimeCall::validate_() { void TimeCall::perform() { this->validate_(); - ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name())); if (this->hour_.has_value()) { ESP_LOGV(TAG, " Hour: %d", *this->hour_); } diff --git a/esphome/components/datetime/time_entity.h b/esphome/components/datetime/time_entity.h index fd31318ce5..64b3b331e9 100644 --- a/esphome/components/datetime/time_entity.h +++ b/esphome/components/datetime/time_entity.h @@ -14,7 +14,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()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ LOG_ENTITY_ICON(TAG, prefix, *(obj)); \ } diff --git a/esphome/components/event/event.cpp b/esphome/components/event/event.cpp index 671e11e7d2..70d48e0c2e 100644 --- a/esphome/components/event/event.cpp +++ b/esphome/components/event/event.cpp @@ -17,11 +17,11 @@ void Event::trigger(const char *event_type) { } } if (found == nullptr) { - ESP_LOGE(TAG, "'%s': invalid event type for trigger(): %s", this->get_name().c_str(), event_type); + ESP_LOGE(TAG, "'%s': invalid event type for trigger(): %s", LOG_STR_ARG(this->get_log_name()), event_type); return; } this->last_event_type_ = found; - ESP_LOGV(TAG, "'%s' >> '%s'", this->get_name().c_str(), this->last_event_type_); + ESP_LOGV(TAG, "'%s' >> '%s'", LOG_STR_ARG(this->get_log_name()), this->last_event_type_); this->event_callback_.call(StringRef(found)); #if defined(USE_EVENT) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_event(this); diff --git a/esphome/components/event/event.h b/esphome/components/event/event.h index 203ee52ac8..2671b10b3a 100644 --- a/esphome/components/event/event.h +++ b/esphome/components/event/event.h @@ -16,7 +16,7 @@ using EventTypes = ConstVector; #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()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ LOG_ENTITY_ICON(TAG, prefix, *(obj)); \ LOG_ENTITY_DEVICE_CLASS(TAG, prefix, *(obj)); \ } diff --git a/esphome/components/fan/fan.cpp b/esphome/components/fan/fan.cpp index 866f5eb0cd..c202378064 100644 --- a/esphome/components/fan/fan.cpp +++ b/esphome/components/fan/fan.cpp @@ -52,14 +52,15 @@ FanCall &FanCall::set_preset_mode(const char *preset_mode, size_t len) { this->preset_mode_ = validated_mode; // Store pointer from traits } else { // Preset mode not found in traits - log warning and don't set - ESP_LOGW(TAG, "%s: Preset mode '%.*s' not supported", this->parent_.get_name().c_str(), (int) len, preset_mode); + ESP_LOGW(TAG, "%s: Preset mode '%.*s' not supported", LOG_STR_ARG(this->parent_.get_log_name()), (int) len, + preset_mode); this->preset_mode_ = nullptr; } return *this; } void FanCall::perform() { - ESP_LOGV(TAG, "'%s' - Setting:", this->parent_.get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting:", LOG_STR_ARG(this->parent_.get_log_name())); this->validate_(); if (this->binary_state_.has_value()) { ESP_LOGV(TAG, " State: %s", ONOFF(*this->binary_state_)); @@ -103,17 +104,17 @@ void FanCall::validate_() { } if (this->oscillating_.has_value() && !traits.supports_oscillation()) { - ESP_LOGW(TAG, "%s: Oscillation not supported", this->parent_.get_name().c_str()); + ESP_LOGW(TAG, "%s: Oscillation not supported", LOG_STR_ARG(this->parent_.get_log_name())); this->oscillating_.reset(); } if (this->speed_.has_value() && !traits.supports_speed()) { - ESP_LOGW(TAG, "%s: Speed control not supported", this->parent_.get_name().c_str()); + ESP_LOGW(TAG, "%s: Speed control not supported", LOG_STR_ARG(this->parent_.get_log_name())); this->speed_.reset(); } if (this->direction_.has_value() && !traits.supports_direction()) { - ESP_LOGW(TAG, "%s: Direction control not supported", this->parent_.get_name().c_str()); + ESP_LOGW(TAG, "%s: Direction control not supported", LOG_STR_ARG(this->parent_.get_log_name())); this->direction_.reset(); } } @@ -221,7 +222,7 @@ void Fan::publish_state() { ESP_LOGV(TAG, "'%s' >>\n" " State: %s", - this->name_.c_str(), ONOFF(this->state)); + LOG_STR_ARG(this->get_log_name()), ONOFF(this->state)); if (traits.supports_speed()) { ESP_LOGV(TAG, " Speed: %d", this->speed); } diff --git a/esphome/components/fan/fan.h b/esphome/components/fan/fan.h index 7e21971639..150d143dbe 100644 --- a/esphome/components/fan/fan.h +++ b/esphome/components/fan/fan.h @@ -12,7 +12,7 @@ namespace esphome::fan { #define LOG_FAN(prefix, type, obj) \ if ((obj) != nullptr) { \ - ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ (obj)->dump_traits_(TAG, prefix); \ } diff --git a/esphome/components/infrared/infrared.cpp b/esphome/components/infrared/infrared.cpp index 9b766a8996..78077af8fb 100644 --- a/esphome/components/infrared/infrared.cpp +++ b/esphome/components/infrared/infrared.cpp @@ -11,7 +11,7 @@ void Infrared::dump_config() { "Infrared '%s'\n" " Supports Transmitter: %s\n" " Supports Receiver: %s", - this->get_name().c_str(), YESNO(this->get_supports_transmitter()), + LOG_STR_ARG(this->get_log_name()), YESNO(this->get_supports_transmitter()), YESNO(this->get_supports_receiver())); } diff --git a/esphome/components/light/addressable_light.cpp b/esphome/components/light/addressable_light.cpp index a6440700fa..86faac3a08 100644 --- a/esphome/components/light/addressable_light.cpp +++ b/esphome/components/light/addressable_light.cpp @@ -10,7 +10,7 @@ void AddressableLight::call_setup() { #ifdef ESPHOME_LOG_HAS_VERY_VERBOSE this->set_interval(5000, [this]() { - const char *name = this->state_parent_ == nullptr ? "" : this->state_parent_->get_name().c_str(); + const char *name = this->state_parent_ == nullptr ? "" : LOG_STR_ARG(this->state_parent_->get_log_name()); ESP_LOGVV(TAG, "Addressable Light '%s' (effect_active=%s)", name, YESNO(this->effect_active_)); for (int i = 0; i < this->size(); i++) { auto color = this->get(i); diff --git a/esphome/components/light/light_call.cpp b/esphome/components/light/light_call.cpp index 0970c513a2..e8a5aae50e 100644 --- a/esphome/components/light/light_call.cpp +++ b/esphome/components/light/light_call.cpp @@ -74,7 +74,7 @@ static void log_percent(const LogString *param, float value) { #endif void LightCall::perform() { - const char *name = this->parent_->get_name().c_str(); + const char *name = LOG_STR_ARG(this->parent_->get_log_name()); LightColorValues v = this->validate_(); const bool publish = this->get_publish_(); @@ -182,7 +182,7 @@ void LightCall::perform() { } void LightCall::log_and_clear_unsupported_(FieldFlags flag, const LogString *feature, bool use_color_mode_log) { - auto *name = this->parent_->get_name().c_str(); + auto *name = LOG_STR_ARG(this->parent_->get_log_name()); if (use_color_mode_log) { log_color_mode_not_supported(name, feature); } else { @@ -192,7 +192,7 @@ void LightCall::log_and_clear_unsupported_(FieldFlags flag, const LogString *fea } LightColorValues LightCall::validate_() { - auto *name = this->parent_->get_name().c_str(); + auto *name = LOG_STR_ARG(this->parent_->get_log_name()); auto traits = this->parent_->get_traits(); // Snapshot before the adjustments below add flags of their own @@ -446,7 +446,7 @@ void LightCall::transform_parameters_(const LightTraits &traits) { !(this->color_mode_ & ColorCapability::COLOR_TEMPERATURE) && // min_mireds > 0.0f && max_mireds > 0.0f) { ESP_LOGV(TAG, "'%s': setting cold/warm white channels using white/color temperature values", - this->parent_->get_name().c_str()); + LOG_STR_ARG(this->parent_->get_log_name())); // Only compute cold_white/warm_white from color_temperature if they're not already explicitly set. // This is important for state restoration, where both color_temperature and cold_white/warm_white // are restored from flash - we want to preserve the saved cold_white/warm_white values. @@ -492,7 +492,7 @@ ColorMode LightCall::compute_color_mode_(const LightTraits &traits) { // Don't change if the current mode is in the intersection (suitable AND supported) if (ColorModeMask::mask_contains(intersection, current_mode)) { - ESP_LOGV(TAG, "'%s': color mode not specified; retaining %s", this->parent_->get_name().c_str(), + ESP_LOGV(TAG, "'%s': color mode not specified; retaining %s", LOG_STR_ARG(this->parent_->get_log_name()), LOG_STR_ARG(color_mode_to_human(current_mode))); return current_mode; } @@ -500,7 +500,7 @@ ColorMode LightCall::compute_color_mode_(const LightTraits &traits) { // Use the preferred suitable mode. if (intersection != 0) { ColorMode mode = ColorModeMask::first_value_from_mask(intersection); - ESP_LOGV(TAG, "'%s': color mode not specified; using %s", this->parent_->get_name().c_str(), + ESP_LOGV(TAG, "'%s': color mode not specified; using %s", LOG_STR_ARG(this->parent_->get_log_name()), LOG_STR_ARG(color_mode_to_human(mode))); return mode; } @@ -508,7 +508,7 @@ ColorMode LightCall::compute_color_mode_(const LightTraits &traits) { // There's no supported mode for this call, so warn, use the current more or a mode at random and let validation strip // out whatever we don't support. auto color_mode = current_mode != ColorMode::UNKNOWN ? current_mode : *supported_modes.begin(); - ESP_LOGW(TAG, "'%s': no suitable color mode supported; defaulting to %s", this->parent_->get_name().c_str(), + ESP_LOGW(TAG, "'%s': no suitable color mode supported; defaulting to %s", LOG_STR_ARG(this->parent_->get_log_name()), LOG_STR_ARG(color_mode_to_human(color_mode))); return color_mode; } @@ -587,7 +587,7 @@ LightCall &LightCall::set_effect(const char *effect, size_t len) { } } if (!found) { - ESP_LOGW(TAG, "'%s': no such effect '%.*s'", this->parent_->get_name().c_str(), (int) len, effect); + ESP_LOGW(TAG, "'%s': no such effect '%.*s'", LOG_STR_ARG(this->parent_->get_log_name()), (int) len, effect); } return *this; } diff --git a/esphome/components/light/light_state.cpp b/esphome/components/light/light_state.cpp index 885440187f..98c953d557 100644 --- a/esphome/components/light/light_state.cpp +++ b/esphome/components/light/light_state.cpp @@ -91,7 +91,7 @@ void LightState::setup() { call.perform(); } void LightState::dump_config() { - ESP_LOGCONFIG(TAG, "Light '%s'", this->get_name().c_str()); + ESP_LOGCONFIG(TAG, "Light '%s'", LOG_STR_ARG(this->get_log_name())); auto traits = this->get_traits(); if (traits.supports_color_capability(ColorCapability::BRIGHTNESS)) { #ifdef USE_LIGHT_GAMMA_LUT diff --git a/esphome/components/lock/lock.cpp b/esphome/components/lock/lock.cpp index aca3a3b024..ff6bb71c29 100644 --- a/esphome/components/lock/lock.cpp +++ b/esphome/components/lock/lock.cpp @@ -30,10 +30,10 @@ void Lock::lock() { this->set_state_(LOCK_STATE_LOCKED); } void Lock::unlock() { this->set_state_(LOCK_STATE_UNLOCKED); } void Lock::open() { if (traits.get_supports_open()) { - ESP_LOGD(TAG, "'%s' Opening.", this->get_name().c_str()); + ESP_LOGD(TAG, "'%s' Opening.", LOG_STR_ARG(this->get_log_name())); this->open_latch(); } else { - ESP_LOGW(TAG, "'%s' Does not support Open.", this->get_name().c_str()); + ESP_LOGW(TAG, "'%s' Does not support Open.", LOG_STR_ARG(this->get_log_name())); } } void Lock::publish_state(LockState state) { @@ -42,7 +42,7 @@ void Lock::publish_state(LockState state) { this->state = state; this->rtc_.save(&this->state); - ESP_LOGV(TAG, "'%s' >> %s", this->name_.c_str(), LOG_STR_ARG(lock_state_to_string(state))); + ESP_LOGV(TAG, "'%s' >> %s", LOG_STR_ARG(this->get_log_name()), LOG_STR_ARG(lock_state_to_string(state))); this->state_callback_.call(state); #if defined(USE_LOCK) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_lock_update(this); @@ -50,7 +50,7 @@ void Lock::publish_state(LockState state) { } void LockCall::perform() { - ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name())); this->validate_(); if (this->state_.has_value()) { ESP_LOGV(TAG, " State: %s", LOG_STR_ARG(lock_state_to_string(*this->state_))); @@ -92,7 +92,7 @@ LockCall &LockCall::set_state(const char *state) { } else if (ESPHOME_strcasecmp_P(state, ESPHOME_PSTR("NONE")) == 0) { this->set_state(LOCK_STATE_NONE); } else { - ESP_LOGW(TAG, "'%s' - Unrecognized state %s", this->parent_->get_name().c_str(), state); + ESP_LOGW(TAG, "'%s' - Unrecognized state %s", LOG_STR_ARG(this->parent_->get_log_name()), state); } return *this; } diff --git a/esphome/components/lock/lock.h b/esphome/components/lock/lock.h index b32d0da8e7..2862c33955 100644 --- a/esphome/components/lock/lock.h +++ b/esphome/components/lock/lock.h @@ -13,7 +13,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()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ LOG_ENTITY_ICON(TAG, prefix, *(obj)); \ if ((obj)->traits.get_assumed_state()) { \ ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \ diff --git a/esphome/components/media_player/media_player.cpp b/esphome/components/media_player/media_player.cpp index 423832dd2f..1716a054c7 100644 --- a/esphome/components/media_player/media_player.cpp +++ b/esphome/components/media_player/media_player.cpp @@ -109,7 +109,7 @@ void MediaPlayerCall::validate_() { } void MediaPlayerCall::perform() { - ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name())); this->validate_(); if (this->command_.has_value()) { const char *command_s = media_player_command_to_string(this->command_.value()); @@ -177,7 +177,7 @@ MediaPlayerCall &MediaPlayerCall::set_command(const char *command) { } else if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR("GROUP_JOIN")) == 0) { this->set_command(MEDIA_PLAYER_COMMAND_GROUP_JOIN); } else { - ESP_LOGW(TAG, "'%s' - Unrecognized command %s", this->parent_->get_name().c_str(), command); + ESP_LOGW(TAG, "'%s' - Unrecognized command %s", LOG_STR_ARG(this->parent_->get_log_name()), command); } return *this; } diff --git a/esphome/components/number/number.cpp b/esphome/components/number/number.cpp index 1d5533c423..d21d757b86 100644 --- a/esphome/components/number/number.cpp +++ b/esphome/components/number/number.cpp @@ -13,7 +13,7 @@ void log_number(const char *tag, const char *prefix, const char *type, Number *o return; } - ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str()); + ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, LOG_STR_ARG(obj->get_log_name())); LOG_ENTITY_ICON(tag, prefix, *obj); LOG_ENTITY_UNIT_OF_MEASUREMENT(tag, prefix, *obj); LOG_ENTITY_DEVICE_CLASS(tag, prefix, *obj); @@ -22,7 +22,7 @@ void log_number(const char *tag, const char *prefix, const char *type, Number *o void Number::publish_state(float state) { this->set_has_state(true); this->state = state; - ESP_LOGV(TAG, "'%s' >> %.2f", this->get_name().c_str(), state); + ESP_LOGV(TAG, "'%s' >> %.2f", LOG_STR_ARG(this->get_log_name()), state); this->state_callback_.call(state); #if defined(USE_NUMBER) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_number_update(this); diff --git a/esphome/components/number/number_call.cpp b/esphome/components/number/number_call.cpp index a928eaf3fa..4079d77522 100644 --- a/esphome/components/number/number_call.cpp +++ b/esphome/components/number/number_call.cpp @@ -8,12 +8,12 @@ ESPHOME_LOG_TAG(TAG, "number"); // Helper functions to reduce code size for logging void NumberCall::log_perform_warning_(const LogString *message) { - ESP_LOGW(TAG, "'%s': %s", this->parent_->get_name().c_str(), LOG_STR_ARG(message)); + ESP_LOGW(TAG, "'%s': %s", LOG_STR_ARG(this->parent_->get_log_name()), LOG_STR_ARG(message)); } void NumberCall::log_perform_warning_value_range_(const LogString *comparison, const LogString *limit_type, float val, float limit) { - ESP_LOGW(TAG, "'%s': %f %s %s %f", this->parent_->get_name().c_str(), val, LOG_STR_ARG(comparison), + ESP_LOGW(TAG, "'%s': %f %s %s %f", LOG_STR_ARG(this->parent_->get_log_name()), val, LOG_STR_ARG(comparison), LOG_STR_ARG(limit_type), limit); } @@ -48,7 +48,7 @@ NumberCall &NumberCall::with_cycle(bool cycle) { void NumberCall::perform() { auto *parent = this->parent_; - const auto *name = parent->get_name().c_str(); + const auto *name = LOG_STR_ARG(parent->get_log_name()); const auto &traits = parent->traits; if (this->operation_ == NUMBER_OP_NONE) { diff --git a/esphome/components/radio_frequency/radio_frequency.cpp b/esphome/components/radio_frequency/radio_frequency.cpp index 231d6c3f89..5f379790f3 100644 --- a/esphome/components/radio_frequency/radio_frequency.cpp +++ b/esphome/components/radio_frequency/radio_frequency.cpp @@ -13,7 +13,7 @@ void RadioFrequency::dump_config() { "Radio Frequency '%s'\n" " Supports Transmitter: %s\n" " Supports Receiver: %s", - this->get_name().c_str(), YESNO(this->get_supports_transmitter()), + LOG_STR_ARG(this->get_log_name()), YESNO(this->get_supports_transmitter()), YESNO(this->get_supports_receiver())); if (this->traits_.get_frequency_min_hz() > 0) { if (this->traits_.get_frequency_min_hz() == this->traits_.get_frequency_max_hz()) { diff --git a/esphome/components/select/select.cpp b/esphome/components/select/select.cpp index 4d77c6d6f6..acbb1b3a91 100644 --- a/esphome/components/select/select.cpp +++ b/esphome/components/select/select.cpp @@ -13,19 +13,19 @@ void Select::publish_state(const char *state) { if (index.has_value()) { this->publish_state(index.value()); } else { - ESP_LOGE(TAG, "'%s': Invalid option %s", this->get_name().c_str(), state); + ESP_LOGE(TAG, "'%s': Invalid option %s", LOG_STR_ARG(this->get_log_name()), state); } } void Select::publish_state(size_t index) { if (!this->has_index(index)) { - ESP_LOGE(TAG, "'%s': Invalid index %zu", this->get_name().c_str(), index); + ESP_LOGE(TAG, "'%s': Invalid index %zu", LOG_STR_ARG(this->get_log_name()), index); return; } const char *option = this->option_at(index); this->set_has_state(true); this->active_index_ = index; - ESP_LOGV(TAG, "'%s' >> %s (%zu)", this->get_name().c_str(), option, index); + ESP_LOGV(TAG, "'%s' >> %s (%zu)", LOG_STR_ARG(this->get_log_name()), option, index); this->state_callback_.call(index); #if defined(USE_SELECT) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_select_update(this); diff --git a/esphome/components/select/select.h b/esphome/components/select/select.h index 2294f34e62..7a801d6b20 100644 --- a/esphome/components/select/select.h +++ b/esphome/components/select/select.h @@ -11,7 +11,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()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ LOG_ENTITY_ICON(TAG, prefix, *(obj)); \ } diff --git a/esphome/components/select/select_call.cpp b/esphome/components/select/select_call.cpp index 167e6769a4..9841dbde79 100644 --- a/esphome/components/select/select_call.cpp +++ b/esphome/components/select/select_call.cpp @@ -40,7 +40,7 @@ SelectCall &SelectCall::with_option(const char *option, size_t len) { SelectCall &SelectCall::with_index(size_t index) { this->operation_ = SELECT_OP_SET; if (index >= this->parent_->size()) { - ESP_LOGW(TAG, "'%s' - Index value %zu out of bounds", this->parent_->get_name().c_str(), index); + ESP_LOGW(TAG, "'%s' - Index value %zu out of bounds", LOG_STR_ARG(this->parent_->get_log_name()), index); this->index_ = nullopt; // Store nullopt for invalid index } else { this->index_ = index; @@ -101,7 +101,7 @@ optional SelectCall::calculate_target_index_(const char *name) { void SelectCall::perform() { auto *parent = this->parent_; - const auto *name = parent->get_name().c_str(); + const auto *name = LOG_STR_ARG(parent->get_log_name()); if (this->operation_ == SELECT_OP_NONE) { ESP_LOGW(TAG, "'%s' - SelectCall performed without selecting an operation", name); diff --git a/esphome/components/sensor/sensor.cpp b/esphome/components/sensor/sensor.cpp index df73e2c481..c235ff08f5 100644 --- a/esphome/components/sensor/sensor.cpp +++ b/esphome/components/sensor/sensor.cpp @@ -19,7 +19,7 @@ void log_sensor(const char *tag, const char *prefix, const char *type, Sensor *o "%s State Class: '%s'\n" "%s Unit of Measurement: '%s'\n" "%s Accuracy Decimals: %d", - prefix, type, obj->get_name().c_str(), prefix, + prefix, type, LOG_STR_ARG(obj->get_log_name()), prefix, 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()); @@ -68,7 +68,7 @@ void Sensor::publish_state(float state) { this->raw_callback_.call(state); #endif - ESP_LOGV(TAG, "'%s': Received new state %f", this->name_.c_str(), state); + ESP_LOGV(TAG, "'%s': Received new state %f", LOG_STR_ARG(this->get_log_name()), state); #ifdef USE_SENSOR_FILTER if (this->filter_list_ == nullptr) { @@ -116,8 +116,8 @@ void Sensor::clear_filters() { void Sensor::internal_send_state_to_frontend(float state) { this->set_has_state(true); this->state = state; - ESP_LOGV(TAG, "'%s' >> %.*f %s", this->get_name().c_str(), std::max(0, (int) this->get_accuracy_decimals()), state, - this->get_unit_of_measurement_ref().c_str()); + ESP_LOGV(TAG, "'%s' >> %.*f %s", LOG_STR_ARG(this->get_log_name()), std::max(0, (int) this->get_accuracy_decimals()), + state, this->get_unit_of_measurement_ref().c_str()); this->callback_.call(state); #if defined(USE_SENSOR) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_sensor_update(this); diff --git a/esphome/components/switch/switch.cpp b/esphome/components/switch/switch.cpp index 179ef2ce35..c5ca8e24be 100644 --- a/esphome/components/switch/switch.cpp +++ b/esphome/components/switch/switch.cpp @@ -17,15 +17,15 @@ void Switch::control(bool target_state) { } } void Switch::turn_on() { - ESP_LOGV(TAG, "'%s' Turning ON.", this->get_name().c_str()); + ESP_LOGV(TAG, "'%s' Turning ON.", LOG_STR_ARG(this->get_log_name())); this->write_state(!this->inverted_); } void Switch::turn_off() { - ESP_LOGV(TAG, "'%s' Turning OFF.", this->get_name().c_str()); + ESP_LOGV(TAG, "'%s' Turning OFF.", LOG_STR_ARG(this->get_log_name())); this->write_state(this->inverted_); } void Switch::toggle() { - ESP_LOGV(TAG, "'%s' Toggling %s.", this->get_name().c_str(), + ESP_LOGV(TAG, "'%s' Toggling %s.", LOG_STR_ARG(this->get_log_name()), this->state ? LOG_STR_LITERAL("OFF") : LOG_STR_LITERAL("ON")); this->write_state(this->inverted_ == this->state); } @@ -62,7 +62,7 @@ void Switch::publish_state(bool state) { if (restore_mode & RESTORE_MODE_PERSISTENT_MASK) this->rtc_.save(&this->state); - ESP_LOGV(TAG, "'%s' >> %s", this->name_.c_str(), ONOFF(this->state)); + ESP_LOGV(TAG, "'%s' >> %s", LOG_STR_ARG(this->get_log_name()), ONOFF(this->state)); this->state_callback_.call(this->state); #if defined(USE_SWITCH) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_switch_update(this); @@ -86,7 +86,7 @@ void log_switch(const char *tag, const char *prefix, const char *type, Switch *o 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), + prefix, type, LOG_STR_ARG(obj->get_log_name()), prefix, LOG_STR_ARG(inverted), LOG_STR_ARG(restore), LOG_STR_ARG(onoff)); // Add optional fields separately diff --git a/esphome/components/text/text.cpp b/esphome/components/text/text.cpp index 58ab300b90..809ee57e0a 100644 --- a/esphome/components/text/text.cpp +++ b/esphome/components/text/text.cpp @@ -15,9 +15,9 @@ void Text::publish_state(const char *state, size_t len) { this->state.assign(state, len); } if (this->traits.get_mode() == TEXT_MODE_PASSWORD) { - ESP_LOGV(TAG, "'%s' >> " LOG_SECRET("'%s'"), this->get_name().c_str(), this->state.c_str()); + ESP_LOGV(TAG, "'%s' >> " LOG_SECRET("'%s'"), LOG_STR_ARG(this->get_log_name()), this->state.c_str()); } else { - ESP_LOGV(TAG, "'%s' >> '%s'", this->get_name().c_str(), this->state.c_str()); + ESP_LOGV(TAG, "'%s' >> '%s'", LOG_STR_ARG(this->get_log_name()), this->state.c_str()); } this->state_callback_.call(this->state); #if defined(USE_TEXT) && defined(USE_CONTROLLER_REGISTRY) diff --git a/esphome/components/text/text.h b/esphome/components/text/text.h index 54afb8db8f..5cb0916a31 100644 --- a/esphome/components/text/text.h +++ b/esphome/components/text/text.h @@ -10,7 +10,7 @@ namespace esphome::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()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ LOG_ENTITY_ICON(TAG, prefix, *(obj)); \ } diff --git a/esphome/components/text/text_call.cpp b/esphome/components/text/text_call.cpp index 93f0610d7d..c4283af318 100644 --- a/esphome/components/text/text_call.cpp +++ b/esphome/components/text/text_call.cpp @@ -17,7 +17,7 @@ TextCall &TextCall::set_value(const char *value, size_t len) { } void TextCall::validate_() { - const auto *name = this->parent_->get_name().c_str(); + const auto *name = LOG_STR_ARG(this->parent_->get_log_name()); if (!this->value_.has_value()) { ESP_LOGW(TAG, "'%s' - No value set for TextCall", name); @@ -42,16 +42,16 @@ void TextCall::validate_() { void TextCall::perform() { this->validate_(); if (!this->value_.has_value()) { - ESP_LOGW(TAG, "'%s' - No value set for TextCall", this->parent_->get_name().c_str()); + ESP_LOGW(TAG, "'%s' - No value set for TextCall", LOG_STR_ARG(this->parent_->get_log_name())); return; } std::string target_value = this->value_.value(); if (this->parent_->traits.get_mode() == TEXT_MODE_PASSWORD) { - ESP_LOGV(TAG, "'%s' - Setting password value: " LOG_SECRET("'%s'"), this->parent_->get_name().c_str(), + ESP_LOGV(TAG, "'%s' - Setting password value: " LOG_SECRET("'%s'"), LOG_STR_ARG(this->parent_->get_log_name()), target_value.c_str()); } else { - ESP_LOGV(TAG, "'%s' - Setting text value: %s", this->parent_->get_name().c_str(), target_value.c_str()); + ESP_LOGV(TAG, "'%s' - Setting text value: %s", LOG_STR_ARG(this->parent_->get_log_name()), target_value.c_str()); } this->parent_->control(target_value); } diff --git a/esphome/components/text_sensor/text_sensor.cpp b/esphome/components/text_sensor/text_sensor.cpp index af4c5fd081..1dde098194 100644 --- a/esphome/components/text_sensor/text_sensor.cpp +++ b/esphome/components/text_sensor/text_sensor.cpp @@ -13,7 +13,7 @@ void log_text_sensor(const char *tag, const char *prefix, const char *type, Text return; } - ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str()); + ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, LOG_STR_ARG(obj->get_log_name())); LOG_ENTITY_DEVICE_CLASS(tag, prefix, *obj); LOG_ENTITY_ICON(tag, prefix, *obj); } @@ -30,7 +30,7 @@ void TextSensor::publish_state(const char *state, size_t len) { #ifdef USE_TEXT_SENSOR_FILTER this->raw_callback_.call(this->state); #endif - ESP_LOGV(TAG, "'%s': Received new state %s", this->name_.c_str(), this->state.c_str()); + ESP_LOGV(TAG, "'%s': Received new state %s", LOG_STR_ARG(this->get_log_name()), this->state.c_str()); this->notify_frontend_(); #ifdef USE_TEXT_SENSOR_FILTER } else { @@ -40,7 +40,7 @@ void TextSensor::publish_state(const char *state, size_t len) { this->raw_state_.assign(state, len); } this->raw_callback_.call(this->raw_state_); - ESP_LOGV(TAG, "'%s': Received new state %s", this->name_.c_str(), this->raw_state_.c_str()); + ESP_LOGV(TAG, "'%s': Received new state %s", LOG_STR_ARG(this->get_log_name()), this->raw_state_.c_str()); this->filter_list_->input(this->raw_state_); } #endif @@ -97,7 +97,7 @@ void TextSensor::internal_send_state_to_frontend(const char *state, size_t len) void TextSensor::notify_frontend_() { this->set_has_state(true); - ESP_LOGV(TAG, "'%s' >> '%s'", this->name_.c_str(), this->state.c_str()); + ESP_LOGV(TAG, "'%s' >> '%s'", LOG_STR_ARG(this->get_log_name()), this->state.c_str()); this->callback_.call(this->state); #if defined(USE_TEXT_SENSOR) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_text_sensor_update(this); diff --git a/esphome/components/update/update_entity.cpp b/esphome/components/update/update_entity.cpp index 33c33ccb62..89608c797d 100644 --- a/esphome/components/update/update_entity.cpp +++ b/esphome/components/update/update_entity.cpp @@ -20,7 +20,7 @@ void UpdateEntity::publish_state() { ESP_LOGV(TAG, "'%s' >>\n" " Current Version: %s", - this->name_.c_str(), this->update_info_.current_version.c_str()); + LOG_STR_ARG(this->get_log_name()), this->update_info_.current_version.c_str()); if (!this->update_info_.md5.empty()) { ESP_LOGV(TAG, " Latest Version: %s", this->update_info_.latest_version.c_str()); diff --git a/esphome/components/valve/valve.cpp b/esphome/components/valve/valve.cpp index a5ad9817df..fdee764936 100644 --- a/esphome/components/valve/valve.cpp +++ b/esphome/components/valve/valve.cpp @@ -42,7 +42,7 @@ ValveCall &ValveCall::set_command(const char *command) { } else if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR("TOGGLE")) == 0) { this->set_command_toggle(); } else { - ESP_LOGW(TAG, "'%s' - Unrecognized command %s", this->parent_->get_name().c_str(), command); + ESP_LOGW(TAG, "'%s' - Unrecognized command %s", LOG_STR_ARG(this->parent_->get_log_name()), command); } return *this; } @@ -67,7 +67,7 @@ ValveCall &ValveCall::set_position(float position) { return *this; } void ValveCall::perform() { - ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name())); auto traits = this->parent_->get_traits(); this->validate_(); if (this->stop_) { @@ -92,16 +92,18 @@ void ValveCall::validate_() { if (this->position_.has_value()) { auto pos = *this->position_; if (!traits.get_supports_position() && pos != VALVE_OPEN && pos != VALVE_CLOSED) { - ESP_LOGW(TAG, "'%s' - This valve device does not support setting position!", this->parent_->get_name().c_str()); + ESP_LOGW(TAG, "'%s' - This valve device does not support setting position!", + LOG_STR_ARG(this->parent_->get_log_name())); this->position_.reset(); } else if (pos < 0.0f || pos > 1.0f) { - ESP_LOGW(TAG, "'%s' - Position %.2f is out of range [0.0 - 1.0]", this->parent_->get_name().c_str(), pos); + ESP_LOGW(TAG, "'%s' - Position %.2f is out of range [0.0 - 1.0]", LOG_STR_ARG(this->parent_->get_log_name()), + pos); this->position_ = clamp(pos, 0.0f, 1.0f); } } if (this->toggle_.has_value()) { if (!traits.get_supports_toggle()) { - ESP_LOGW(TAG, "'%s' - This valve device does not support toggle!", this->parent_->get_name().c_str()); + ESP_LOGW(TAG, "'%s' - This valve device does not support toggle!", LOG_STR_ARG(this->parent_->get_log_name())); this->toggle_.reset(); } } @@ -123,7 +125,7 @@ ValveCall &ValveCall::set_stop(bool stop) { void Valve::publish_state(bool save) { this->position = clamp(this->position, 0.0f, 1.0f); - ESP_LOGV(TAG, "'%s' >>", this->name_.c_str()); + ESP_LOGV(TAG, "'%s' >>", LOG_STR_ARG(this->get_log_name())); auto traits = this->get_traits(); if (traits.get_supports_position()) { ESP_LOGV(TAG, " Position: %.0f%%", this->position * 100.0f); diff --git a/esphome/components/valve/valve.h b/esphome/components/valve/valve.h index 183680e5e4..2316870d3b 100644 --- a/esphome/components/valve/valve.h +++ b/esphome/components/valve/valve.h @@ -14,7 +14,7 @@ const extern float VALVE_CLOSED; #define LOG_VALVE(prefix, type, obj) \ if ((obj) != nullptr) { \ - ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \ + ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \ auto traits_ = (obj)->get_traits(); \ if (traits_.get_is_assumed_state()) { \ ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \ diff --git a/esphome/components/water_heater/water_heater.cpp b/esphome/components/water_heater/water_heater.cpp index e5236a0491..cd5020a582 100644 --- a/esphome/components/water_heater/water_heater.cpp +++ b/esphome/components/water_heater/water_heater.cpp @@ -15,7 +15,7 @@ ESPHOME_LOG_TAG(TAG, "water_heater"); void log_water_heater(const char *tag, const char *prefix, const char *type, WaterHeater *obj) { if (obj != nullptr) { - ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str()); + ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, LOG_STR_ARG(obj->get_log_name())); } } @@ -44,7 +44,7 @@ WaterHeaterCall &WaterHeaterCall::set_mode(const char *mode, size_t len) { } else if (len == 3 && ESPHOME_strncasecmp_P(mode, ESPHOME_PSTR("GAS"), 3) == 0) { this->set_mode(WATER_HEATER_MODE_GAS); } else { - ESP_LOGW(TAG, "'%s' - Unrecognized mode %.*s", this->parent_->get_name().c_str(), (int) len, mode); + ESP_LOGW(TAG, "'%s' - Unrecognized mode %.*s", LOG_STR_ARG(this->parent_->get_log_name()), (int) len, mode); } return *this; } @@ -85,7 +85,7 @@ WaterHeaterCall &WaterHeaterCall::set_on(bool on) { } void WaterHeaterCall::perform() { - ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name())); this->validate_(); if (this->mode_.has_value()) { ESP_LOGV(TAG, " Mode: %s", LOG_STR_ARG(water_heater_mode_to_string(*this->mode_))); @@ -113,7 +113,7 @@ void WaterHeaterCall::validate_() { auto traits = this->parent_->get_traits(); if (this->mode_.has_value()) { if (!traits.supports_mode(*this->mode_)) { - ESP_LOGW(TAG, "'%s' - Mode %" PRIu32 " not supported", this->parent_->get_name().c_str(), + ESP_LOGW(TAG, "'%s' - Mode %" PRIu32 " not supported", LOG_STR_ARG(this->parent_->get_log_name()), static_cast(*this->mode_)); this->mode_.reset(); } @@ -121,34 +121,36 @@ void WaterHeaterCall::validate_() { if (!std::isnan(this->target_temperature_)) { if (traits.get_supports_two_point_target_temperature()) { ESP_LOGW(TAG, "'%s' - Cannot set target temperature for device with two-point target temperature", - this->parent_->get_name().c_str()); + LOG_STR_ARG(this->parent_->get_log_name())); this->target_temperature_ = NAN; } else if (this->target_temperature_ < traits.get_min_temperature() || this->target_temperature_ > traits.get_max_temperature()) { - ESP_LOGW(TAG, "'%s' - Target temperature %.1f is out of range [%.1f - %.1f]", this->parent_->get_name().c_str(), - this->target_temperature_, traits.get_min_temperature(), traits.get_max_temperature()); + ESP_LOGW(TAG, "'%s' - Target temperature %.1f is out of range [%.1f - %.1f]", + LOG_STR_ARG(this->parent_->get_log_name()), this->target_temperature_, traits.get_min_temperature(), + traits.get_max_temperature()); this->target_temperature_ = std::max(traits.get_min_temperature(), std::min(this->target_temperature_, traits.get_max_temperature())); } } if (!std::isnan(this->target_temperature_low_) || !std::isnan(this->target_temperature_high_)) { if (!traits.get_supports_two_point_target_temperature()) { - ESP_LOGW(TAG, "'%s' - Cannot set low/high target temperature", this->parent_->get_name().c_str()); + ESP_LOGW(TAG, "'%s' - Cannot set low/high target temperature", LOG_STR_ARG(this->parent_->get_log_name())); this->target_temperature_low_ = NAN; this->target_temperature_high_ = NAN; } } if (!std::isnan(this->target_temperature_low_) && !std::isnan(this->target_temperature_high_)) { if (this->target_temperature_low_ > this->target_temperature_high_) { - ESP_LOGW(TAG, "'%s' - Target temperature low %.2f must be less than high %.2f", this->parent_->get_name().c_str(), - this->target_temperature_low_, this->target_temperature_high_); + ESP_LOGW(TAG, "'%s' - Target temperature low %.2f must be less than high %.2f", + LOG_STR_ARG(this->parent_->get_log_name()), this->target_temperature_low_, + this->target_temperature_high_); this->target_temperature_low_ = NAN; this->target_temperature_high_ = NAN; } } if (!traits.get_supports_away_mode()) { if (this->state_ & WATER_HEATER_STATE_AWAY) { - ESP_LOGW(TAG, "'%s' - Away mode not supported", this->parent_->get_name().c_str()); + ESP_LOGW(TAG, "'%s' - Away mode not supported", LOG_STR_ARG(this->parent_->get_log_name())); } this->state_ &= ~WATER_HEATER_STATE_AWAY; this->state_mask_ &= ~WATER_HEATER_STATE_AWAY; @@ -166,7 +168,7 @@ void WaterHeater::publish_state() { ESP_LOGV(TAG, "'%s' >>\n" " Mode: %s", - this->name_.c_str(), LOG_STR_ARG(water_heater_mode_to_string(this->mode_))); + LOG_STR_ARG(this->get_log_name()), LOG_STR_ARG(water_heater_mode_to_string(this->mode_))); if (!std::isnan(this->current_temperature_)) { ESP_LOGV(TAG, " Current Temperature: %.2f°C", this->current_temperature_); }