mirror of
https://github.com/esphome/esphome.git
synced 2025-10-13 23:33:48 +01:00
wip
This commit is contained in:
@@ -453,10 +453,9 @@ std::string WebServer::sensor_json(sensor::Sensor *obj, float value, JsonDetail
|
|||||||
|
|
||||||
const auto uom_ref = obj->get_unit_of_measurement_ref();
|
const auto uom_ref = obj->get_unit_of_measurement_ref();
|
||||||
|
|
||||||
// Build JSON directly inline
|
set_json_value(root, obj, "sensor", value, start_config);
|
||||||
std::string state =
|
root["state"] =
|
||||||
std::isnan(value) ? "NA" : value_accuracy_with_uom_to_string(value, obj->get_accuracy_decimals(), uom_ref);
|
std::isnan(value) ? "NA" : value_accuracy_with_uom_to_string(value, obj->get_accuracy_decimals(), uom_ref);
|
||||||
set_json_icon_state_value(root, obj, "sensor", state, value, start_config);
|
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
this->add_sorting_info_(root, obj);
|
this->add_sorting_info_(root, obj);
|
||||||
if (!uom_ref.empty())
|
if (!uom_ref.empty())
|
||||||
@@ -796,8 +795,7 @@ std::string WebServer::light_json(light::LightState *obj, JsonDetail start_confi
|
|||||||
json::JsonBuilder builder;
|
json::JsonBuilder builder;
|
||||||
JsonObject root = builder.root();
|
JsonObject root = builder.root();
|
||||||
|
|
||||||
set_json_id(root, obj, "light", start_config);
|
set_json_value(root, obj, "light", obj->remote_values.is_on() ? "ON" : "OFF", start_config);
|
||||||
root["state"] = obj->remote_values.is_on() ? "ON" : "OFF";
|
|
||||||
|
|
||||||
light::LightJSONSchema::dump_json(*obj, root);
|
light::LightJSONSchema::dump_json(*obj, root);
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
@@ -945,6 +943,12 @@ std::string WebServer::number_json(number::Number *obj, float value, JsonDetail
|
|||||||
const auto uom_ref = obj->traits.get_unit_of_measurement_ref();
|
const auto uom_ref = obj->traits.get_unit_of_measurement_ref();
|
||||||
|
|
||||||
set_json_id(root, obj, "number", start_config);
|
set_json_id(root, obj, "number", start_config);
|
||||||
|
root["value"] = std::isnan(value)
|
||||||
|
? "\"NaN\""
|
||||||
|
: value_accuracy_to_string(value, step_to_accuracy_decimals(obj->traits.get_step()));
|
||||||
|
root["state"] = std::isnan(value) ? "NA"
|
||||||
|
: value_accuracy_with_uom_to_string(
|
||||||
|
value, step_to_accuracy_decimals(obj->traits.get_step()), uom_ref);
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
root["min_value"] =
|
root["min_value"] =
|
||||||
value_accuracy_to_string(obj->traits.get_min_value(), step_to_accuracy_decimals(obj->traits.get_step()));
|
value_accuracy_to_string(obj->traits.get_min_value(), step_to_accuracy_decimals(obj->traits.get_step()));
|
||||||
@@ -956,14 +960,6 @@ std::string WebServer::number_json(number::Number *obj, float value, JsonDetail
|
|||||||
root["uom"] = uom_ref;
|
root["uom"] = uom_ref;
|
||||||
this->add_sorting_info_(root, obj);
|
this->add_sorting_info_(root, obj);
|
||||||
}
|
}
|
||||||
if (std::isnan(value)) {
|
|
||||||
root["value"] = "\"NaN\"";
|
|
||||||
root["state"] = "NA";
|
|
||||||
} else {
|
|
||||||
root["value"] = value_accuracy_to_string(value, step_to_accuracy_decimals(obj->traits.get_step()));
|
|
||||||
root["state"] =
|
|
||||||
value_accuracy_with_uom_to_string(value, step_to_accuracy_decimals(obj->traits.get_step()), uom_ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.serialize();
|
return builder.serialize();
|
||||||
}
|
}
|
||||||
@@ -1739,8 +1735,8 @@ std::string WebServer::update_json(update::UpdateEntity *obj, JsonDetail start_c
|
|||||||
json::JsonBuilder builder;
|
json::JsonBuilder builder;
|
||||||
JsonObject root = builder.root();
|
JsonObject root = builder.root();
|
||||||
|
|
||||||
set_json_value(root, obj, "update", obj->update_info.latest_version, start_config);
|
set_json_icon_state_value(root, obj, "update", update_state_to_string(obj->state), obj->update_info.latest_version,
|
||||||
root["state"] = update_state_to_string(obj->state);
|
start_config);
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
root["current_version"] = obj->update_info.current_version;
|
root["current_version"] = obj->update_info.current_version;
|
||||||
root["title"] = obj->update_info.title;
|
root["title"] = obj->update_info.title;
|
||||||
|
Reference in New Issue
Block a user