Move the entity domain and MQTT log conversions to the stacked PR

This commit is contained in:
J. Nick Koston
2026-10-12 17:27:40 -10:00
parent 522395de11
commit c4c19a00e0
61 changed files with 145 additions and 159 deletions
@@ -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)", LOG_STR_ARG(this->get_log_name()),
ESP_LOGV(TAG, "'%s' >> %s (was %s)", this->get_name().c_str(),
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;
@@ -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, LOG_STR_ARG(obj->get_log_name()));
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
LOG_ENTITY_DEVICE_CLASS(tag, prefix, *obj);
}
@@ -38,7 +38,7 @@ bool BinarySensor::set_new_state(const optional<bool> &new_state) {
#if defined(USE_BINARY_SENSOR) && defined(USE_CONTROLLER_REGISTRY)
ControllerRegistry::notify_binary_sensor_update(this);
#endif
ESP_LOGV(TAG, "'%s' >> %s", LOG_STR_ARG(this->get_log_name()), ONOFFMAYBE(new_state));
ESP_LOGV(TAG, "'%s' >> %s", this->get_name().c_str(), ONOFFMAYBE(new_state));
return true;
}
return false;
+2 -2
View File
@@ -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, LOG_STR_ARG(obj->get_log_name()));
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
LOG_ENTITY_ICON(tag, prefix, *obj);
}
void Button::press() {
ESP_LOGV(TAG, "'%s' Pressed.", LOG_STR_ARG(this->get_log_name()));
ESP_LOGV(TAG, "'%s' Pressed.", this->get_name().c_str());
this->press_action();
this->press_callback_.call();
}
+7 -10
View File
@@ -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", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
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", LOG_STR_ARG(this->parent_->get_log_name()), (int) len, mode);
ESP_LOGW(TAG, "'%s' - Unrecognized mode %.*s", this->parent_->get_name().c_str(), (int) len, mode);
return *this;
}
@@ -214,8 +214,7 @@ 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", LOG_STR_ARG(this->parent_->get_log_name()), (int) len,
custom_fan_mode);
ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %.*s", this->parent_->get_name().c_str(), (int) len, custom_fan_mode);
return *this;
}
@@ -253,8 +252,7 @@ ClimateCall &ClimateCall::set_preset(const char *custom_preset, size_t len) {
this->preset_.reset();
return *this;
}
ESP_LOGW(TAG, "'%s' - Unrecognized preset %.*s", LOG_STR_ARG(this->parent_->get_log_name()), (int) len,
custom_preset);
ESP_LOGW(TAG, "'%s' - Unrecognized preset %.*s", this->parent_->get_name().c_str(), (int) len, custom_preset);
return *this;
}
@@ -282,8 +280,7 @@ ClimateCall &ClimateCall::set_swing_mode(const char *swing_mode, size_t len) {
return *this;
}
}
ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %.*s", LOG_STR_ARG(this->parent_->get_log_name()), (int) len,
swing_mode);
ESP_LOGW(TAG, "'%s' - Unrecognized swing mode %.*s", this->parent_->get_name().c_str(), (int) len, swing_mode);
return *this;
}
@@ -431,7 +428,7 @@ void Climate::save_state_(const ClimateTraits &traits) {
void Climate::publish_state() {
this->set_has_state(true);
ESP_LOGV(TAG, "'%s' >>", LOG_STR_ARG(this->get_log_name()));
ESP_LOGV(TAG, "'%s' >>", this->name_.c_str());
auto traits = this->get_traits();
ESP_LOGV(TAG, " Mode: %s", LOG_STR_ARG(climate_mode_to_string(this->mode)));
@@ -552,7 +549,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", LOG_STR_ARG(climate->get_log_name()),
ESP_LOGW(TAG, "'%s' - Saved mode %s is no longer supported, keeping %s", climate->get_name().c_str(),
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 |
+1 -1
View File
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
}
class Climate;
+4 -4
View File
@@ -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", LOG_STR_ARG(this->parent_->get_log_name()), command);
ESP_LOGW(TAG, "'%s' - Unrecognized command %s", this->parent_->get_name().c_str(), command);
}
return *this;
}
@@ -68,7 +68,7 @@ CoverCall &CoverCall::set_tilt(float tilt) {
return *this;
}
void CoverCall::perform() {
ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
auto traits = this->parent_->get_traits();
this->validate_();
if (this->stop_) {
@@ -94,7 +94,7 @@ const optional<float> &CoverCall::get_tilt() const { return this->tilt_; }
const optional<bool> &CoverCall::get_toggle() const { return this->toggle_; }
void CoverCall::validate_() {
auto traits = this->parent_->get_traits();
const char *name = LOG_STR_ARG(this->parent_->get_log_name());
const char *name = this->parent_->get_name().c_str();
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' >>", LOG_STR_ARG(this->get_log_name()));
ESP_LOGV(TAG, "'%s' >>", this->name_.c_str());
auto traits = this->get_traits();
if (traits.get_supports_position()) {
ESP_LOGV(TAG, " Position: %.0f%%", this->position * 100.0f);
+1 -1
View File
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
auto traits_ = (obj)->get_traits(); \
if (traits_.get_is_assumed_state()) { \
ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \
+2 -2
View File
@@ -30,7 +30,7 @@ void DateEntity::publish_state() {
return;
}
this->set_has_state(true);
ESP_LOGV(TAG, "'%s' >> %d-%d-%d", LOG_STR_ARG(this->get_log_name()), this->year_, this->month_, this->day_);
ESP_LOGV(TAG, "'%s' >> %d-%d-%d", this->get_name().c_str(), 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", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
if (this->year_.has_value()) {
ESP_LOGV(TAG, " Year: %d", *this->year_);
+1 -1
View File
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
LOG_ENTITY_ICON(TAG, prefix, *(obj)); \
}
@@ -45,7 +45,7 @@ void DateTimeEntity::publish_state() {
return;
}
this->set_has_state(true);
ESP_LOGV(TAG, "'%s' >> %04u-%02u-%02u %02d:%02d:%02d", LOG_STR_ARG(this->get_log_name()), this->year_, this->month_,
ESP_LOGV(TAG, "'%s' >> %04u-%02u-%02u %02d:%02d:%02d", this->get_name().c_str(), 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", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
if (this->year_.has_value()) {
ESP_LOGV(TAG, " Year: %d", *this->year_);
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
LOG_ENTITY_ICON(TAG, prefix, *(obj)); \
}
+2 -2
View File
@@ -26,7 +26,7 @@ void TimeEntity::publish_state() {
return;
}
this->set_has_state(true);
ESP_LOGV(TAG, "'%s' >> %02d:%02d:%02d", LOG_STR_ARG(this->get_log_name()), this->hour_, this->minute_, this->second_);
ESP_LOGV(TAG, "'%s' >> %02d:%02d:%02d", this->get_name().c_str(), 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", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
if (this->hour_.has_value()) {
ESP_LOGV(TAG, " Hour: %d", *this->hour_);
}
+1 -1
View File
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
LOG_ENTITY_ICON(TAG, prefix, *(obj)); \
}
+2 -2
View File
@@ -17,11 +17,11 @@ void Event::trigger(const char *event_type) {
}
}
if (found == nullptr) {
ESP_LOGE(TAG, "'%s': invalid event type for trigger(): %s", LOG_STR_ARG(this->get_log_name()), event_type);
ESP_LOGE(TAG, "'%s': invalid event type for trigger(): %s", this->get_name().c_str(), event_type);
return;
}
this->last_event_type_ = found;
ESP_LOGV(TAG, "'%s' >> '%s'", LOG_STR_ARG(this->get_log_name()), this->last_event_type_);
ESP_LOGV(TAG, "'%s' >> '%s'", this->get_name().c_str(), this->last_event_type_);
this->event_callback_.call(StringRef(found));
#if defined(USE_EVENT) && defined(USE_CONTROLLER_REGISTRY)
ControllerRegistry::notify_event(this);
+1 -1
View File
@@ -16,7 +16,7 @@ using EventTypes = ConstVector<const char *, true>;
#define LOG_EVENT(prefix, type, obj) \
if ((obj) != nullptr) { \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), LOG_STR_ARG((obj)->get_log_name())); \
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)); \
}
+6 -7
View File
@@ -52,15 +52,14 @@ 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", LOG_STR_ARG(this->parent_.get_log_name()), (int) len,
preset_mode);
ESP_LOGW(TAG, "%s: Preset mode '%.*s' not supported", this->parent_.get_name().c_str(), (int) len, preset_mode);
this->preset_mode_ = nullptr;
}
return *this;
}
void FanCall::perform() {
ESP_LOGV(TAG, "'%s' - Setting:", LOG_STR_ARG(this->parent_.get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting:", this->parent_.get_name().c_str());
this->validate_();
if (this->binary_state_.has_value()) {
ESP_LOGV(TAG, " State: %s", ONOFF(*this->binary_state_));
@@ -104,17 +103,17 @@ void FanCall::validate_() {
}
if (this->oscillating_.has_value() && !traits.supports_oscillation()) {
ESP_LOGW(TAG, "%s: Oscillation not supported", LOG_STR_ARG(this->parent_.get_log_name()));
ESP_LOGW(TAG, "%s: Oscillation not supported", this->parent_.get_name().c_str());
this->oscillating_.reset();
}
if (this->speed_.has_value() && !traits.supports_speed()) {
ESP_LOGW(TAG, "%s: Speed control not supported", LOG_STR_ARG(this->parent_.get_log_name()));
ESP_LOGW(TAG, "%s: Speed control not supported", this->parent_.get_name().c_str());
this->speed_.reset();
}
if (this->direction_.has_value() && !traits.supports_direction()) {
ESP_LOGW(TAG, "%s: Direction control not supported", LOG_STR_ARG(this->parent_.get_log_name()));
ESP_LOGW(TAG, "%s: Direction control not supported", this->parent_.get_name().c_str());
this->direction_.reset();
}
}
@@ -222,7 +221,7 @@ void Fan::publish_state() {
ESP_LOGV(TAG,
"'%s' >>\n"
" State: %s",
LOG_STR_ARG(this->get_log_name()), ONOFF(this->state));
this->name_.c_str(), ONOFF(this->state));
if (traits.supports_speed()) {
ESP_LOGV(TAG, " Speed: %d", this->speed);
}
+1 -1
View File
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
(obj)->dump_traits_(TAG, prefix); \
}
+1 -1
View File
@@ -11,7 +11,7 @@ void Infrared::dump_config() {
"Infrared '%s'\n"
" Supports Transmitter: %s\n"
" Supports Receiver: %s",
LOG_STR_ARG(this->get_log_name()), YESNO(this->get_supports_transmitter()),
this->get_name().c_str(), YESNO(this->get_supports_transmitter()),
YESNO(this->get_supports_receiver()));
}
@@ -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 ? "" : LOG_STR_ARG(this->state_parent_->get_log_name());
const char *name = this->state_parent_ == nullptr ? "" : this->state_parent_->get_name().c_str();
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);
+8 -8
View File
@@ -74,7 +74,7 @@ static void log_percent(const LogString *param, float value) {
#endif
void LightCall::perform() {
const char *name = LOG_STR_ARG(this->parent_->get_log_name());
const char *name = this->parent_->get_name().c_str();
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 = LOG_STR_ARG(this->parent_->get_log_name());
auto *name = this->parent_->get_name().c_str();
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 = LOG_STR_ARG(this->parent_->get_log_name());
auto *name = this->parent_->get_name().c_str();
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",
LOG_STR_ARG(this->parent_->get_log_name()));
this->parent_->get_name().c_str());
// 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", LOG_STR_ARG(this->parent_->get_log_name()),
ESP_LOGV(TAG, "'%s': color mode not specified; retaining %s", this->parent_->get_name().c_str(),
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", LOG_STR_ARG(this->parent_->get_log_name()),
ESP_LOGV(TAG, "'%s': color mode not specified; using %s", this->parent_->get_name().c_str(),
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", LOG_STR_ARG(this->parent_->get_log_name()),
ESP_LOGW(TAG, "'%s': no suitable color mode supported; defaulting to %s", this->parent_->get_name().c_str(),
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'", LOG_STR_ARG(this->parent_->get_log_name()), (int) len, effect);
ESP_LOGW(TAG, "'%s': no such effect '%.*s'", this->parent_->get_name().c_str(), (int) len, effect);
}
return *this;
}
+1 -1
View File
@@ -91,7 +91,7 @@ void LightState::setup() {
call.perform();
}
void LightState::dump_config() {
ESP_LOGCONFIG(TAG, "Light '%s'", LOG_STR_ARG(this->get_log_name()));
ESP_LOGCONFIG(TAG, "Light '%s'", this->get_name().c_str());
auto traits = this->get_traits();
if (traits.supports_color_capability(ColorCapability::BRIGHTNESS)) {
#ifdef USE_LIGHT_GAMMA_LUT
+5 -5
View File
@@ -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.", LOG_STR_ARG(this->get_log_name()));
ESP_LOGD(TAG, "'%s' Opening.", this->get_name().c_str());
this->open_latch();
} else {
ESP_LOGW(TAG, "'%s' Does not support Open.", LOG_STR_ARG(this->get_log_name()));
ESP_LOGW(TAG, "'%s' Does not support Open.", this->get_name().c_str());
}
}
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", LOG_STR_ARG(this->get_log_name()), LOG_STR_ARG(lock_state_to_string(state)));
ESP_LOGV(TAG, "'%s' >> %s", this->name_.c_str(), 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", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
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", LOG_STR_ARG(this->parent_->get_log_name()), state);
ESP_LOGW(TAG, "'%s' - Unrecognized state %s", this->parent_->get_name().c_str(), state);
}
return *this;
}
+1 -1
View File
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
LOG_ENTITY_ICON(TAG, prefix, *(obj)); \
if ((obj)->traits.get_assumed_state()) { \
ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \
@@ -109,7 +109,7 @@ void MediaPlayerCall::validate_() {
}
void MediaPlayerCall::perform() {
ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
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", LOG_STR_ARG(this->parent_->get_log_name()), command);
ESP_LOGW(TAG, "'%s' - Unrecognized command %s", this->parent_->get_name().c_str(), command);
}
return *this;
}
@@ -59,9 +59,9 @@ void MQTTAlarmControlPanelComponent::setup() {
if (!root.isNull()) {
const char *state = root[ESPHOME_F("state")];
if (state == nullptr) {
ESP_LOGW(TAG, "'%s': JSON payload missing 'state' key", LOG_STR_ARG(this->log_name_()));
ESP_LOGW(TAG, "'%s': JSON payload missing 'state' key", this->friendly_name_().c_str());
} else if (!apply_command(call, state)) {
ESP_LOGW(TAG, "'%s': Received unknown state in JSON payload: %s", LOG_STR_ARG(this->log_name_()), state);
ESP_LOGW(TAG, "'%s': Received unknown state in JSON payload: %s", this->friendly_name_().c_str(), state);
} else {
const char *code = root[ESPHOME_F("code")];
if (code != nullptr) {
@@ -70,14 +70,14 @@ void MQTTAlarmControlPanelComponent::setup() {
}
}
} else if (!apply_command(call, payload.c_str())) {
ESP_LOGW(TAG, "'%s': Received unknown command payload %s", LOG_STR_ARG(this->log_name_()), payload.c_str());
ESP_LOGW(TAG, "'%s': Received unknown command payload %s", this->friendly_name_().c_str(), payload.c_str());
}
call.perform();
});
}
void MQTTAlarmControlPanelComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT alarm_control_panel '%s':", LOG_STR_ARG(this->alarm_control_panel_->get_log_name()));
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"
@@ -18,7 +18,7 @@ void MQTTBinarySensorComponent::setup() {
}
void MQTTBinarySensorComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Binary Sensor '%s':", LOG_STR_ARG(this->binary_sensor_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Binary Sensor '%s':", this->binary_sensor_->get_name().c_str());
LOG_MQTT_COMPONENT(true, false);
}
MQTTBinarySensorComponent::MQTTBinarySensorComponent(binary_sensor::BinarySensor *binary_sensor)
+2 -2
View File
@@ -19,13 +19,13 @@ void MQTTButtonComponent::setup() {
if (payload == "PRESS") {
this->button_->press();
} else {
ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", LOG_STR_ARG(this->log_name_()), payload.c_str());
ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", this->friendly_name_().c_str(), payload.c_str());
this->status_momentary_warning(5000);
}
});
}
void MQTTButtonComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Button '%s': ", LOG_STR_ARG(this->button_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Button '%s': ", this->button_->get_name().c_str());
LOG_MQTT_COMPONENT(false, true);
}
+2 -6
View File
@@ -186,11 +186,11 @@ bool MQTTComponent::send_discovery_() {
StringRef discovery_topic = this->get_discovery_topic_to_(discovery_topic_buf, discovery_info);
if (discovery_info.clean) {
ESP_LOGV(TAG, "'%s': Cleaning discovery", LOG_STR_ARG(this->log_name_()));
ESP_LOGV(TAG, "'%s': Cleaning discovery", this->friendly_name_().c_str());
return global_mqtt_client->publish(discovery_topic.c_str(), "", 0, this->qos_, true);
}
ESP_LOGV(TAG, "'%s': Sending discovery", LOG_STR_ARG(this->log_name_()));
ESP_LOGV(TAG, "'%s': Sending discovery", this->friendly_name_().c_str());
// NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
return global_mqtt_client->publish_json(
@@ -413,11 +413,7 @@ void MQTTComponent::schedule_resend_state() { this->resend_state_ = true; }
bool MQTTComponent::is_connected_() const { return global_mqtt_client->is_connected(); }
// Pull these properties from EntityBase if not overridden
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
const StringRef &MQTTComponent::friendly_name_() const { return this->get_entity()->get_name(); }
#pragma GCC diagnostic pop
const LogString *MQTTComponent::log_name_() const { return this->get_entity()->get_log_name(); }
StringRef MQTTComponent::get_default_object_id_to_(std::span<char, OBJECT_ID_MAX_LEN> buf) const {
return this->get_entity()->get_object_id_to(buf);
}
+1 -3
View File
@@ -300,9 +300,7 @@ class MQTTComponent : public Component {
*/
virtual const EntityBase *get_entity() const = 0;
/// Entity name for a "%s" log argument.
const LogString *log_name_() const;
ESPDEPRECATED("Use log_name_() for logging. Removed in 2027.5.0", "2026.11.0")
/// Get the friendly name of this MQTT component.
const StringRef &friendly_name_() const;
/// Get the icon field of this component into a stack buffer
+1 -1
View File
@@ -63,7 +63,7 @@ void MQTTCoverComponent::setup() {
}
void MQTTCoverComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT cover '%s':", LOG_STR_ARG(this->cover_->get_log_name()));
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);
+1 -1
View File
@@ -35,7 +35,7 @@ void MQTTDateComponent::setup() {
}
void MQTTDateComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Date '%s':", LOG_STR_ARG(this->date_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Date '%s':", this->date_->get_name().c_str());
LOG_MQTT_COMPONENT(true, true);
}
+1 -1
View File
@@ -46,7 +46,7 @@ void MQTTDateTimeComponent::setup() {
}
void MQTTDateTimeComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT DateTime '%s':", LOG_STR_ARG(this->datetime_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT DateTime '%s':", this->datetime_->get_name().c_str());
LOG_MQTT_COMPONENT(true, true);
}
+1 -1
View File
@@ -28,7 +28,7 @@ void MQTTEventComponent::setup() {
}
void MQTTEventComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Event '%s': ", LOG_STR_ARG(this->event_->get_log_name()));
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);
+9 -9
View File
@@ -32,15 +32,15 @@ void MQTTFanComponent::setup() {
auto val = parse_on_off(payload.c_str());
switch (val) {
case PARSE_ON:
ESP_LOGD(TAG, "'%s' Turning Fan ON.", LOG_STR_ARG(this->log_name_()));
ESP_LOGD(TAG, "'%s' Turning Fan ON.", this->friendly_name_().c_str());
this->state_->turn_on().perform();
break;
case PARSE_OFF:
ESP_LOGD(TAG, "'%s' Turning Fan OFF.", LOG_STR_ARG(this->log_name_()));
ESP_LOGD(TAG, "'%s' Turning Fan OFF.", this->friendly_name_().c_str());
this->state_->turn_off().perform();
break;
case PARSE_TOGGLE:
ESP_LOGD(TAG, "'%s' Toggling Fan.", LOG_STR_ARG(this->log_name_()));
ESP_LOGD(TAG, "'%s' Toggling Fan.", this->friendly_name_().c_str());
this->state_->toggle().perform();
break;
case PARSE_NONE:
@@ -56,11 +56,11 @@ void MQTTFanComponent::setup() {
auto val = parse_on_off(payload.c_str(), "forward", "reverse");
switch (val) {
case PARSE_ON:
ESP_LOGD(TAG, "'%s': Setting direction FORWARD", LOG_STR_ARG(this->log_name_()));
ESP_LOGD(TAG, "'%s': Setting direction FORWARD", this->friendly_name_().c_str());
this->state_->make_call().set_direction(fan::FanDirection::FORWARD).perform();
break;
case PARSE_OFF:
ESP_LOGD(TAG, "'%s': Setting direction REVERSE", LOG_STR_ARG(this->log_name_()));
ESP_LOGD(TAG, "'%s': Setting direction REVERSE", this->friendly_name_().c_str());
this->state_->make_call().set_direction(fan::FanDirection::REVERSE).perform();
break;
case PARSE_TOGGLE:
@@ -83,11 +83,11 @@ void MQTTFanComponent::setup() {
auto val = parse_on_off(payload.c_str(), "oscillate_on", "oscillate_off");
switch (val) {
case PARSE_ON:
ESP_LOGD(TAG, "'%s': Setting oscillating ON", LOG_STR_ARG(this->log_name_()));
ESP_LOGD(TAG, "'%s': Setting oscillating ON", this->friendly_name_().c_str());
this->state_->make_call().set_oscillating(true).perform();
break;
case PARSE_OFF:
ESP_LOGD(TAG, "'%s': Setting oscillating OFF", LOG_STR_ARG(this->log_name_()));
ESP_LOGD(TAG, "'%s': Setting oscillating OFF", this->friendly_name_().c_str());
this->state_->make_call().set_oscillating(false).perform();
break;
case PARSE_TOGGLE:
@@ -125,7 +125,7 @@ void MQTTFanComponent::setup() {
}
void MQTTFanComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Fan '%s': ", LOG_STR_ARG(this->state_->get_log_name()));
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,
@@ -168,7 +168,7 @@ void MQTTFanComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig
bool MQTTFanComponent::publish_state() {
char topic_buf[MQTT_DEFAULT_TOPIC_MAX_LEN];
const char *state_s = this->state_->state ? "ON" : "OFF";
ESP_LOGD(TAG, "'%s' Sending state %s.", LOG_STR_ARG(this->state_->get_log_name()), state_s);
ESP_LOGD(TAG, "'%s' Sending state %s.", this->state_->get_name().c_str(), state_s);
this->publish(this->get_state_topic_to_(topic_buf), state_s);
bool failed = false;
if (this->state_->get_traits().supports_direction()) {
+1 -1
View File
@@ -88,7 +88,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':", LOG_STR_ARG(this->state_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Light '%s':", this->state_->get_name().c_str());
LOG_MQTT_COMPONENT(true, true);
}
+2 -2
View File
@@ -24,7 +24,7 @@ void MQTTLockComponent::setup() {
} else if (ESPHOME_strcasecmp_P(payload.c_str(), ESPHOME_PSTR("OPEN")) == 0) {
this->lock_->open();
} else {
ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", LOG_STR_ARG(this->log_name_()), payload.c_str());
ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", this->friendly_name_().c_str(), payload.c_str());
this->status_momentary_warning(5000);
}
});
@@ -32,7 +32,7 @@ void MQTTLockComponent::setup() {
[this](LockState /*state*/) { this->defer(SEND_DEFER_ID, [this]() { this->publish_state(); }); });
}
void MQTTLockComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Lock '%s': ", LOG_STR_ARG(this->lock_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Lock '%s': ", this->lock_->get_name().c_str());
LOG_MQTT_COMPONENT(true, true);
}
+1 -1
View File
@@ -33,7 +33,7 @@ void MQTTNumberComponent::setup() {
}
void MQTTNumberComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Number '%s':", LOG_STR_ARG(this->number_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Number '%s':", this->number_->get_name().c_str());
LOG_MQTT_COMPONENT(true, false);
}
+1 -1
View File
@@ -24,7 +24,7 @@ void MQTTSelectComponent::setup() {
}
void MQTTSelectComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Select '%s':", LOG_STR_ARG(this->select_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Select '%s':", this->select_->get_name().c_str());
LOG_MQTT_COMPONENT(true, false);
}
+1 -1
View File
@@ -25,7 +25,7 @@ void MQTTSensorComponent::setup() {
}
void MQTTSensorComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Sensor '%s':", LOG_STR_ARG(this->sensor_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Sensor '%s':", this->sensor_->get_name().c_str());
if (this->get_expire_after() > 0) {
ESP_LOGCONFIG(TAG, " Expire After: %" PRIu32 "s", this->get_expire_after() / 1000);
}
+2 -2
View File
@@ -28,7 +28,7 @@ void MQTTSwitchComponent::setup() {
break;
case PARSE_NONE:
default:
ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", LOG_STR_ARG(this->log_name_()), payload.c_str());
ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", this->friendly_name_().c_str(), payload.c_str());
this->status_momentary_warning(5000);
break;
}
@@ -37,7 +37,7 @@ void MQTTSwitchComponent::setup() {
[this](bool enabled) { this->defer(SEND_DEFER_ID, [this, enabled]() { this->publish_state(enabled); }); });
}
void MQTTSwitchComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Switch '%s': ", LOG_STR_ARG(this->switch_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Switch '%s': ", this->switch_->get_name().c_str());
LOG_MQTT_COMPONENT(true, true);
}
+1 -1
View File
@@ -29,7 +29,7 @@ void MQTTTextComponent::setup() {
}
void MQTTTextComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT text '%s':", LOG_STR_ARG(this->text_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT text '%s':", this->text_->get_name().c_str());
LOG_MQTT_COMPONENT(true, true);
}
+1 -1
View File
@@ -21,7 +21,7 @@ void MQTTTextSensor::setup() {
}
void MQTTTextSensor::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Text Sensor '%s':", LOG_STR_ARG(this->sensor_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Text Sensor '%s':", this->sensor_->get_name().c_str());
LOG_MQTT_COMPONENT(true, false);
}
+1 -1
View File
@@ -35,7 +35,7 @@ void MQTTTimeComponent::setup() {
}
void MQTTTimeComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT Time '%s':", LOG_STR_ARG(this->time_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Time '%s':", this->time_->get_name().c_str());
LOG_MQTT_COMPONENT(true, true);
}
+2 -2
View File
@@ -19,7 +19,7 @@ void MQTTUpdateComponent::setup() {
if (payload == "INSTALL") {
this->update_->perform();
} else {
ESP_LOGW(TAG, "'%s': Received unknown update payload: %s", LOG_STR_ARG(this->log_name_()), payload.c_str());
ESP_LOGW(TAG, "'%s': Received unknown update payload: %s", this->friendly_name_().c_str(), payload.c_str());
this->status_momentary_warning(5000);
}
});
@@ -49,7 +49,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': ", LOG_STR_ARG(this->update_->get_log_name()));
ESP_LOGCONFIG(TAG, "MQTT Update '%s': ", this->update_->get_name().c_str());
LOG_MQTT_COMPONENT(true, true);
}
+1 -1
View File
@@ -51,7 +51,7 @@ void MQTTValveComponent::setup() {
}
void MQTTValveComponent::dump_config() {
ESP_LOGCONFIG(TAG, "MQTT valve '%s':", LOG_STR_ARG(this->valve_->get_log_name()));
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);
+2 -2
View File
@@ -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, LOG_STR_ARG(obj->get_log_name()));
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);
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", LOG_STR_ARG(this->get_log_name()), state);
ESP_LOGV(TAG, "'%s' >> %.2f", this->get_name().c_str(), state);
this->state_callback_.call(state);
#if defined(USE_NUMBER) && defined(USE_CONTROLLER_REGISTRY)
ControllerRegistry::notify_number_update(this);
+3 -3
View File
@@ -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", LOG_STR_ARG(this->parent_->get_log_name()), LOG_STR_ARG(message));
ESP_LOGW(TAG, "'%s': %s", this->parent_->get_name().c_str(), 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", LOG_STR_ARG(this->parent_->get_log_name()), val, LOG_STR_ARG(comparison),
ESP_LOGW(TAG, "'%s': %f %s %s %f", this->parent_->get_name().c_str(), 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 = LOG_STR_ARG(parent->get_log_name());
const auto *name = parent->get_name().c_str();
const auto &traits = parent->traits;
if (this->operation_ == NUMBER_OP_NONE) {
@@ -13,7 +13,7 @@ void RadioFrequency::dump_config() {
"Radio Frequency '%s'\n"
" Supports Transmitter: %s\n"
" Supports Receiver: %s",
LOG_STR_ARG(this->get_log_name()), YESNO(this->get_supports_transmitter()),
this->get_name().c_str(), 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()) {
+3 -3
View File
@@ -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", LOG_STR_ARG(this->get_log_name()), state);
ESP_LOGE(TAG, "'%s': Invalid option %s", this->get_name().c_str(), state);
}
}
void Select::publish_state(size_t index) {
if (!this->has_index(index)) {
ESP_LOGE(TAG, "'%s': Invalid index %zu", LOG_STR_ARG(this->get_log_name()), index);
ESP_LOGE(TAG, "'%s': Invalid index %zu", this->get_name().c_str(), index);
return;
}
const char *option = this->option_at(index);
this->set_has_state(true);
this->active_index_ = index;
ESP_LOGV(TAG, "'%s' >> %s (%zu)", LOG_STR_ARG(this->get_log_name()), option, index);
ESP_LOGV(TAG, "'%s' >> %s (%zu)", this->get_name().c_str(), option, index);
this->state_callback_.call(index);
#if defined(USE_SELECT) && defined(USE_CONTROLLER_REGISTRY)
ControllerRegistry::notify_select_update(this);
+1 -1
View File
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
LOG_ENTITY_ICON(TAG, prefix, *(obj)); \
}
+2 -2
View File
@@ -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", LOG_STR_ARG(this->parent_->get_log_name()), index);
ESP_LOGW(TAG, "'%s' - Index value %zu out of bounds", this->parent_->get_name().c_str(), index);
this->index_ = nullopt; // Store nullopt for invalid index
} else {
this->index_ = index;
@@ -101,7 +101,7 @@ optional<size_t> SelectCall::calculate_target_index_(const char *name) {
void SelectCall::perform() {
auto *parent = this->parent_;
const auto *name = LOG_STR_ARG(parent->get_log_name());
const auto *name = parent->get_name().c_str();
if (this->operation_ == SELECT_OP_NONE) {
ESP_LOGW(TAG, "'%s' - SelectCall performed without selecting an operation", name);
+4 -4
View File
@@ -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, LOG_STR_ARG(obj->get_log_name()), prefix,
prefix, type, obj->get_name().c_str(), 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", LOG_STR_ARG(this->get_log_name()), state);
ESP_LOGV(TAG, "'%s': Received new state %f", this->name_.c_str(), 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", LOG_STR_ARG(this->get_log_name()), std::max(0, (int) this->get_accuracy_decimals()),
state, this->get_unit_of_measurement_ref().c_str());
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());
this->callback_.call(state);
#if defined(USE_SENSOR) && defined(USE_CONTROLLER_REGISTRY)
ControllerRegistry::notify_sensor_update(this);
+5 -5
View File
@@ -17,15 +17,15 @@ void Switch::control(bool target_state) {
}
}
void Switch::turn_on() {
ESP_LOGV(TAG, "'%s' Turning ON.", LOG_STR_ARG(this->get_log_name()));
ESP_LOGV(TAG, "'%s' Turning ON.", this->get_name().c_str());
this->write_state(!this->inverted_);
}
void Switch::turn_off() {
ESP_LOGV(TAG, "'%s' Turning OFF.", LOG_STR_ARG(this->get_log_name()));
ESP_LOGV(TAG, "'%s' Turning OFF.", this->get_name().c_str());
this->write_state(this->inverted_);
}
void Switch::toggle() {
ESP_LOGV(TAG, "'%s' Toggling %s.", LOG_STR_ARG(this->get_log_name()),
ESP_LOGV(TAG, "'%s' Toggling %s.", this->get_name().c_str(),
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", LOG_STR_ARG(this->get_log_name()), ONOFF(this->state));
ESP_LOGV(TAG, "'%s' >> %s", this->name_.c_str(), 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, LOG_STR_ARG(obj->get_log_name()), prefix, LOG_STR_ARG(inverted), LOG_STR_ARG(restore),
prefix, type, obj->get_name().c_str(), prefix, LOG_STR_ARG(inverted), LOG_STR_ARG(restore),
LOG_STR_ARG(onoff));
// Add optional fields separately
+2 -2
View File
@@ -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'"), LOG_STR_ARG(this->get_log_name()), this->state.c_str());
ESP_LOGV(TAG, "'%s' >> " LOG_SECRET("'%s'"), this->get_name().c_str(), this->state.c_str());
} else {
ESP_LOGV(TAG, "'%s' >> '%s'", LOG_STR_ARG(this->get_log_name()), this->state.c_str());
ESP_LOGV(TAG, "'%s' >> '%s'", this->get_name().c_str(), this->state.c_str());
}
this->state_callback_.call(this->state);
#if defined(USE_TEXT) && defined(USE_CONTROLLER_REGISTRY)
+1 -1
View File
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
LOG_ENTITY_ICON(TAG, prefix, *(obj)); \
}
+4 -4
View File
@@ -17,7 +17,7 @@ TextCall &TextCall::set_value(const char *value, size_t len) {
}
void TextCall::validate_() {
const auto *name = LOG_STR_ARG(this->parent_->get_log_name());
const auto *name = this->parent_->get_name().c_str();
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", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGW(TAG, "'%s' - No value set for TextCall", this->parent_->get_name().c_str());
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'"), LOG_STR_ARG(this->parent_->get_log_name()),
ESP_LOGV(TAG, "'%s' - Setting password value: " LOG_SECRET("'%s'"), this->parent_->get_name().c_str(),
target_value.c_str());
} else {
ESP_LOGV(TAG, "'%s' - Setting text value: %s", LOG_STR_ARG(this->parent_->get_log_name()), target_value.c_str());
ESP_LOGV(TAG, "'%s' - Setting text value: %s", this->parent_->get_name().c_str(), target_value.c_str());
}
this->parent_->control(target_value);
}
@@ -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, LOG_STR_ARG(obj->get_log_name()));
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);
}
@@ -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", LOG_STR_ARG(this->get_log_name()), this->state.c_str());
ESP_LOGV(TAG, "'%s': Received new state %s", this->name_.c_str(), 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", LOG_STR_ARG(this->get_log_name()), this->raw_state_.c_str());
ESP_LOGV(TAG, "'%s': Received new state %s", this->name_.c_str(), 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'", LOG_STR_ARG(this->get_log_name()), this->state.c_str());
ESP_LOGV(TAG, "'%s' >> '%s'", this->name_.c_str(), this->state.c_str());
this->callback_.call(this->state);
#if defined(USE_TEXT_SENSOR) && defined(USE_CONTROLLER_REGISTRY)
ControllerRegistry::notify_text_sensor_update(this);
+1 -1
View File
@@ -20,7 +20,7 @@ void UpdateEntity::publish_state() {
ESP_LOGV(TAG,
"'%s' >>\n"
" Current Version: %s",
LOG_STR_ARG(this->get_log_name()), this->update_info_.current_version.c_str());
this->name_.c_str(), 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());
+6 -8
View File
@@ -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", LOG_STR_ARG(this->parent_->get_log_name()), command);
ESP_LOGW(TAG, "'%s' - Unrecognized command %s", this->parent_->get_name().c_str(), command);
}
return *this;
}
@@ -67,7 +67,7 @@ ValveCall &ValveCall::set_position(float position) {
return *this;
}
void ValveCall::perform() {
ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
auto traits = this->parent_->get_traits();
this->validate_();
if (this->stop_) {
@@ -92,18 +92,16 @@ 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!",
LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGW(TAG, "'%s' - This valve device does not support setting position!", this->parent_->get_name().c_str());
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]", LOG_STR_ARG(this->parent_->get_log_name()),
pos);
ESP_LOGW(TAG, "'%s' - Position %.2f is out of range [0.0 - 1.0]", this->parent_->get_name().c_str(), 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!", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGW(TAG, "'%s' - This valve device does not support toggle!", this->parent_->get_name().c_str());
this->toggle_.reset();
}
}
@@ -125,7 +123,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' >>", LOG_STR_ARG(this->get_log_name()));
ESP_LOGV(TAG, "'%s' >>", this->name_.c_str());
auto traits = this->get_traits();
if (traits.get_supports_position()) {
ESP_LOGV(TAG, " Position: %.0f%%", this->position * 100.0f);
+1 -1
View File
@@ -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), LOG_STR_ARG((obj)->get_log_name())); \
ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
auto traits_ = (obj)->get_traits(); \
if (traits_.get_is_assumed_state()) { \
ESP_LOGCONFIG(TAG, "%s Assumed State: YES", prefix); \
@@ -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, LOG_STR_ARG(obj->get_log_name()));
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());
}
}
@@ -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", LOG_STR_ARG(this->parent_->get_log_name()), (int) len, mode);
ESP_LOGW(TAG, "'%s' - Unrecognized mode %.*s", this->parent_->get_name().c_str(), (int) len, mode);
}
return *this;
}
@@ -85,7 +85,7 @@ WaterHeaterCall &WaterHeaterCall::set_on(bool on) {
}
void WaterHeaterCall::perform() {
ESP_LOGV(TAG, "'%s' - Setting", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGV(TAG, "'%s' - Setting", this->parent_->get_name().c_str());
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", LOG_STR_ARG(this->parent_->get_log_name()),
ESP_LOGW(TAG, "'%s' - Mode %" PRIu32 " not supported", this->parent_->get_name().c_str(),
static_cast<uint32_t>(*this->mode_));
this->mode_.reset();
}
@@ -121,36 +121,34 @@ 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",
LOG_STR_ARG(this->parent_->get_log_name()));
this->parent_->get_name().c_str());
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]",
LOG_STR_ARG(this->parent_->get_log_name()), this->target_temperature_, traits.get_min_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());
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", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGW(TAG, "'%s' - Cannot set low/high target temperature", this->parent_->get_name().c_str());
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",
LOG_STR_ARG(this->parent_->get_log_name()), 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_);
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", LOG_STR_ARG(this->parent_->get_log_name()));
ESP_LOGW(TAG, "'%s' - Away mode not supported", this->parent_->get_name().c_str());
}
this->state_ &= ~WATER_HEATER_STATE_AWAY;
this->state_mask_ &= ~WATER_HEATER_STATE_AWAY;
@@ -168,7 +166,7 @@ void WaterHeater::publish_state() {
ESP_LOGV(TAG,
"'%s' >>\n"
" Mode: %s",
LOG_STR_ARG(this->get_log_name()), LOG_STR_ARG(water_heater_mode_to_string(this->mode_)));
this->name_.c_str(), 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_);
}