Webserver float to string fix (#6507)

This commit is contained in:
RFDarter 2024-04-10 01:33:26 +02:00 committed by GitHub
parent e5e8bc8515
commit b4b4e81c1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 4 deletions

View File

@ -851,9 +851,12 @@ std::string WebServer::number_json(number::Number *obj, float value, JsonDetail
return json::build_json([obj, value, start_config](JsonObject root) {
set_json_id(root, obj, "number-" + obj->get_object_id(), start_config);
if (start_config == DETAIL_ALL) {
root["min_value"] = obj->traits.get_min_value();
root["max_value"] = obj->traits.get_max_value();
root["step"] = obj->traits.get_step();
root["min_value"] =
value_accuracy_to_string(obj->traits.get_min_value(), step_to_accuracy_decimals(obj->traits.get_step()));
root["max_value"] =
value_accuracy_to_string(obj->traits.get_max_value(), step_to_accuracy_decimals(obj->traits.get_step()));
root["step"] =
value_accuracy_to_string(obj->traits.get_step(), step_to_accuracy_decimals(obj->traits.get_step()));
root["mode"] = (int) obj->traits.get_mode();
if (!obj->traits.get_unit_of_measurement().empty())
root["uom"] = obj->traits.get_unit_of_measurement();
@ -862,7 +865,7 @@ std::string WebServer::number_json(number::Number *obj, float value, JsonDetail
root["value"] = "\"NaN\"";
root["state"] = "NA";
} else {
root["value"] = value;
root["value"] = value_accuracy_to_string(value, step_to_accuracy_decimals(obj->traits.get_step()));
std::string state = value_accuracy_to_string(value, step_to_accuracy_decimals(obj->traits.get_step()));
if (!obj->traits.get_unit_of_measurement().empty())
state += " " + obj->traits.get_unit_of_measurement();