From cea677bb6afc96e50885cc6d347ca0faf165a939 Mon Sep 17 00:00:00 2001 From: Richard Mitchell <richard.j.mitchell@gmail.com> Date: Mon, 24 Sep 2018 21:40:01 +0100 Subject: [PATCH] Default to something sensible for last udpated time --- sensors.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sensors.go b/sensors.go index 766cf4b..db80efb 100644 --- a/sensors.go +++ b/sensors.go @@ -142,7 +142,9 @@ func (c sensorCollector) recordSensor(sensor hue.Sensor, sensorName string, devi c.sensorValue.With(sensorLabels).Set(sensorValue) c.sensorBattery.With(sensorLabels).Set(float64(sensor.Config.Battery)) - c.sensorLastUpdated.With(sensorLabels).Set(float64(sensor.State.LastUpdated.Unix())) + // let's set a sensible minimum for last updated here: if your sensor last updated before 1970, + // something's clearly not right. No need to set it to 1969 /BCE/. + c.sensorLastUpdated.With(sensorLabels).Set(float64(max(sensor.State.LastUpdated.Unix(), 0))) if sensor.Config.On { c.sensorOn.With(sensorLabels).Set(1) } else { -- GitLab