1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

_strtod_l

This commit is contained in:
J. Nick Koston
2026-01-31 19:12:30 -06:00
parent dfaabfc98a
commit d12e2fea3d
5 changed files with 28 additions and 14 deletions

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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<int>(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<int>(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);

View File

@@ -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);
}
}