From be647cce78c6d9735bee539ba2d55df0dae2a86a Mon Sep 17 00:00:00 2001 From: Sab44 <64696149+Sab44@users.noreply.github.com> Date: Tue, 23 Sep 2025 10:46:06 +0200 Subject: [PATCH] Provide fixed unit for sensors in data.json (#1876) * Remove redundant second null check for sensor value * Add base formatted raw values to data.json for consistent units * Update HttpServer.cs --------- Co-authored-by: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com> --- LibreHardwareMonitor/UI/SensorNode.cs | 2 +- LibreHardwareMonitor/Utilities/HttpServer.cs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/LibreHardwareMonitor/UI/SensorNode.cs b/LibreHardwareMonitor/UI/SensorNode.cs index 3cd878e..22e723e 100644 --- a/LibreHardwareMonitor/UI/SensorNode.cs +++ b/LibreHardwareMonitor/UI/SensorNode.cs @@ -243,7 +243,7 @@ public class SensorNode : Node } case SensorType.TimeSpan: { - return value.HasValue ? string.Format(Format, TimeSpan.FromSeconds(value.Value)) : "-"; + return string.Format(Format, TimeSpan.FromSeconds(value.Value)); } default: { diff --git a/LibreHardwareMonitor/Utilities/HttpServer.cs b/LibreHardwareMonitor/Utilities/HttpServer.cs index c8f5d04..8f3db35 100644 --- a/LibreHardwareMonitor/Utilities/HttpServer.cs +++ b/LibreHardwareMonitor/Utilities/HttpServer.cs @@ -627,9 +627,17 @@ public class HttpServer case SensorNode sensorNode: jsonNode["SensorId"] = sensorNode.Sensor.Identifier.ToString(); jsonNode["Type"] = sensorNode.Sensor.SensorType.ToString(); + + // Formatted values, e.g. Throughput will be measured in KB/s or MB/s depending on the value jsonNode["Min"] = sensorNode.Min; jsonNode["Value"] = sensorNode.Value; jsonNode["Max"] = sensorNode.Max; + + // Unformatted values for external systems to have consistent readings, e.g. Throughput will always be measured in B/s + jsonNode["RawMin"] = string.Format(sensorNode.Format, sensorNode.Sensor.Min); + jsonNode["RawValue"] = string.Format(sensorNode.Format, sensorNode.Sensor.Value); + jsonNode["RawMax"] = string.Format(sensorNode.Format, sensorNode.Sensor.Max); + jsonNode["ImageURL"] = "images/transparent.png"; break; case HardwareNode hardwareNode: