From 8766932739414ea0f664fd72eb5477e579c776e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Rasmussen?= Date: Tue, 26 Jul 2022 12:12:19 +0200 Subject: [PATCH] Ignore temperature magic value -128 --- pkg/temperature/ds18b20.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/temperature/ds18b20.go b/pkg/temperature/ds18b20.go index cbe5115..968376a 100644 --- a/pkg/temperature/ds18b20.go +++ b/pkg/temperature/ds18b20.go @@ -223,12 +223,12 @@ func read(sensor string) (int64, error) { raw := string(data) if !strings.Contains(raw, " YES") { - return 0.0, fmt.Errorf("%w: checksum failed [%v]", ErrReadSensor, raw) + return 0.0, fmt.Errorf("%v: %w: checksum failed [%v]", sensor, ErrReadSensor, raw) } i := strings.LastIndex(raw, "t=") if i == -1 { - return 0.0, fmt.Errorf("%w: t= not found in [%v]", ErrReadSensor, raw) + return 0.0, fmt.Errorf("%v: %w: t= not found in [%v]", sensor, ErrReadSensor, raw) } c, err := strconv.ParseInt(raw[i+2:len(raw)-1], 10, 64) @@ -236,5 +236,10 @@ func read(sensor string) (int64, error) { return 0.0, err } + // Ignore magic value -128 + if c == -128000 { + return 0.0, fmt.Errorf("%v: magic value -128 detected", sensor) + } + return c, nil }