From d12e2fea3d6b265a51d016148bf0e8cb4a0863e1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 31 Jan 2026 19:12:30 -0600 Subject: [PATCH] _strtod_l --- esphome/components/climate/climate.cpp | 17 +++++++++-------- esphome/components/cover/cover.cpp | 4 ++-- esphome/components/number/number.cpp | 2 +- esphome/components/sensor/sensor.cpp | 16 ++++++++++++++-- esphome/components/valve/valve.cpp | 3 ++- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/esphome/components/climate/climate.cpp b/esphome/components/climate/climate.cpp index 209a8a8760..bc644cd893 100644 --- a/esphome/components/climate/climate.cpp +++ b/esphome/components/climate/climate.cpp @@ -75,13 +75,13 @@ void ClimateCall::perform() { ESP_LOGD(TAG, " Swing: %s", LOG_STR_ARG(swing_mode_s)); } if (this->target_temperature_.has_value()) { - ESP_LOGD(TAG, " Target Temperature: %s%d.%d", DECIMAL_1(*this->target_temperature_)); + ESP_LOGD(TAG, " Target Temperature: %s%d.%02d", DECIMAL_2(*this->target_temperature_)); } if (this->target_temperature_low_.has_value()) { - ESP_LOGD(TAG, " Target Temperature Low: %s%d.%d", DECIMAL_1(*this->target_temperature_low_)); + ESP_LOGD(TAG, " Target Temperature Low: %s%d.%02d", DECIMAL_2(*this->target_temperature_low_)); } if (this->target_temperature_high_.has_value()) { - ESP_LOGD(TAG, " Target Temperature High: %s%d.%d", DECIMAL_1(*this->target_temperature_high_)); + ESP_LOGD(TAG, " Target Temperature High: %s%d.%02d", DECIMAL_2(*this->target_temperature_high_)); } if (this->target_humidity_.has_value()) { ESP_LOGD(TAG, " Target Humidity: %d%%", (int) *this->target_humidity_); @@ -161,7 +161,8 @@ void ClimateCall::validate_() { float low = *this->target_temperature_low_; float high = *this->target_temperature_high_; if (low > high) { - ESP_LOGW(TAG, " Target temperature low %s%d.%d must be less than high %s%d.%d", DECIMAL_1(low), DECIMAL_1(high)); + ESP_LOGW(TAG, " Target temperature low %s%d.%02d must be less than high %s%d.%02d", DECIMAL_2(low), + DECIMAL_2(high)); this->target_temperature_low_.reset(); this->target_temperature_high_.reset(); } @@ -458,14 +459,14 @@ void Climate::publish_state() { ESP_LOGD(TAG, " Swing Mode: %s", LOG_STR_ARG(climate_swing_mode_to_string(this->swing_mode))); } if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_TEMPERATURE)) { - ESP_LOGD(TAG, " Current Temperature: %s%d.%d°C", DECIMAL_1(this->current_temperature)); + ESP_LOGD(TAG, " Current Temperature: %s%d.%02d°C", DECIMAL_2(this->current_temperature)); } if (traits.has_feature_flags(CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE | CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE)) { - ESP_LOGD(TAG, " Target Temperature: Low: %s%d.%d°C High: %s%d.%d°C", DECIMAL_1(this->target_temperature_low), - DECIMAL_1(this->target_temperature_high)); + ESP_LOGD(TAG, " Target Temperature: Low: %s%d.%02d°C High: %s%d.%02d°C", DECIMAL_2(this->target_temperature_low), + DECIMAL_2(this->target_temperature_high)); } else { - ESP_LOGD(TAG, " Target Temperature: %s%d.%d°C", DECIMAL_1(this->target_temperature)); + ESP_LOGD(TAG, " Target Temperature: %s%d.%02d°C", DECIMAL_2(this->target_temperature)); } if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_HUMIDITY)) { ESP_LOGD(TAG, " Current Humidity: %d%%", (int) this->current_humidity); diff --git a/esphome/components/cover/cover.cpp b/esphome/components/cover/cover.cpp index 9d42759dad..13a1d8ab23 100644 --- a/esphome/components/cover/cover.cpp +++ b/esphome/components/cover/cover.cpp @@ -105,7 +105,7 @@ void CoverCall::validate_() { ESP_LOGW(TAG, "'%s': position unsupported", name); this->position_.reset(); } else if (pos < 0.0f || pos > 1.0f) { - ESP_LOGW(TAG, "'%s': position %.2f out of range", name, pos); + ESP_LOGW(TAG, "'%s': position %s%d.%02d out of range", name, DECIMAL_2(pos)); this->position_ = clamp(pos, 0.0f, 1.0f); } } @@ -115,7 +115,7 @@ void CoverCall::validate_() { ESP_LOGW(TAG, "'%s': tilt unsupported", name); this->tilt_.reset(); } else if (tilt < 0.0f || tilt > 1.0f) { - ESP_LOGW(TAG, "'%s': tilt %.2f out of range", name, tilt); + ESP_LOGW(TAG, "'%s': tilt %s%d.%02d out of range", name, DECIMAL_2(tilt)); this->tilt_ = clamp(tilt, 0.0f, 1.0f); } } diff --git a/esphome/components/number/number.cpp b/esphome/components/number/number.cpp index 1c4126496c..7e3c1fdbd9 100644 --- a/esphome/components/number/number.cpp +++ b/esphome/components/number/number.cpp @@ -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_LOGD(TAG, "'%s' >> %.2f", this->get_name().c_str(), state); + ESP_LOGD(TAG, "'%s' >> %s%d.%02d", this->get_name().c_str(), DECIMAL_2(state)); this->state_callback_.call(state); #if defined(USE_NUMBER) && defined(USE_CONTROLLER_REGISTRY) ControllerRegistry::notify_number_update(this); diff --git a/esphome/components/sensor/sensor.cpp b/esphome/components/sensor/sensor.cpp index 99e00f26b7..42431f0431 100644 --- a/esphome/components/sensor/sensor.cpp +++ b/esphome/components/sensor/sensor.cpp @@ -115,8 +115,20 @@ float Sensor::get_raw_state() const { return this->raw_state; } void Sensor::internal_send_state_to_frontend(float state) { this->set_has_state(true); this->state = state; - ESP_LOGD(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()); + // Use integer formatting to avoid pulling in _dtoa_r (~3.4KB) + // Format based on accuracy_decimals: 0 = integer, 1 = 1 decimal, 2+ = 2 decimals + int decimals = std::max(0, (int) this->get_accuracy_decimals()); + if (decimals == 0) { + ESP_LOGD(TAG, "'%s' >> %d %s", this->get_name().c_str(), (int) state, this->get_unit_of_measurement_ref().c_str()); + } else if (decimals == 1) { + int scaled = static_cast(state * 10.0f); + ESP_LOGD(TAG, "'%s' >> %s%d.%d %s", this->get_name().c_str(), scaled < 0 ? "-" : "", std::abs(scaled / 10), + std::abs(scaled % 10), this->get_unit_of_measurement_ref().c_str()); + } else { + int scaled = static_cast(state * 100.0f); + ESP_LOGD(TAG, "'%s' >> %s%d.%02d %s", this->get_name().c_str(), scaled < 0 ? "-" : "", std::abs(scaled / 100), + std::abs(scaled % 100), 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/valve/valve.cpp b/esphome/components/valve/valve.cpp index 26f4755b9d..904573aa53 100644 --- a/esphome/components/valve/valve.cpp +++ b/esphome/components/valve/valve.cpp @@ -96,7 +96,8 @@ void ValveCall::validate_() { 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]", this->parent_->get_name().c_str(), pos); + ESP_LOGW(TAG, "'%s' - Position %s%d.%02d is out of range [0.0 - 1.0]", this->parent_->get_name().c_str(), + DECIMAL_2(pos)); this->position_ = clamp(pos, 0.0f, 1.0f); } }