mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Webserver float to string fix (#6507)
This commit is contained in:
parent
e5e8bc8515
commit
b4b4e81c1c
1 changed files with 7 additions and 4 deletions
|
@ -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) {
|
return json::build_json([obj, value, start_config](JsonObject root) {
|
||||||
set_json_id(root, obj, "number-" + obj->get_object_id(), start_config);
|
set_json_id(root, obj, "number-" + obj->get_object_id(), start_config);
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
root["min_value"] = obj->traits.get_min_value();
|
root["min_value"] =
|
||||||
root["max_value"] = obj->traits.get_max_value();
|
value_accuracy_to_string(obj->traits.get_min_value(), step_to_accuracy_decimals(obj->traits.get_step()));
|
||||||
root["step"] = 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();
|
root["mode"] = (int) obj->traits.get_mode();
|
||||||
if (!obj->traits.get_unit_of_measurement().empty())
|
if (!obj->traits.get_unit_of_measurement().empty())
|
||||||
root["uom"] = obj->traits.get_unit_of_measurement();
|
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["value"] = "\"NaN\"";
|
||||||
root["state"] = "NA";
|
root["state"] = "NA";
|
||||||
} else {
|
} 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()));
|
std::string state = value_accuracy_to_string(value, step_to_accuracy_decimals(obj->traits.get_step()));
|
||||||
if (!obj->traits.get_unit_of_measurement().empty())
|
if (!obj->traits.get_unit_of_measurement().empty())
|
||||||
state += " " + obj->traits.get_unit_of_measurement();
|
state += " " + obj->traits.get_unit_of_measurement();
|
||||||
|
|
Loading…
Reference in a new issue