diff --git a/host/host.go b/host/host.go index a312eda9b..319e52197 100644 --- a/host/host.go +++ b/host/host.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "math" "os" "runtime" "time" @@ -60,7 +61,20 @@ func (u UserStat) String() string { } func (t TemperatureStat) String() string { - s, _ := json.Marshal(t) + x := t + if math.IsNaN(x.Low) { + x.Low = 0 + } + if math.IsNaN(x.High) { + x.High = 0 + } + if math.IsNaN(x.Critical) { + x.Critical = 0 + } + if math.IsNaN(x.Alarm) { + x.Alarm = 0 + } + s, _ := json.Marshal(x) return string(s) } diff --git a/host/host_linux.go b/host/host_linux.go index ef736db22..262c3d579 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -9,6 +9,7 @@ import ( "encoding/binary" "fmt" "io" + "math" "os" "path/filepath" "regexp" @@ -512,15 +513,15 @@ func optionalValueReadFromFile(filename string) float64 { // Check if file exists if _, err := os.Stat(filename); os.IsNotExist(err) { - return 0 + return math.NaN() } if raw, err = os.ReadFile(filename); err != nil { - return 0 + return math.NaN() } if value, err = strconv.ParseFloat(strings.TrimSpace(string(raw)), 64); err != nil { - return 0 + return math.NaN() } return value