From b1c9e324a03cc42744f6d1779b904aa648f3501e Mon Sep 17 00:00:00 2001 From: Ted Pearson <1477390+tedpearson@users.noreply.github.com> Date: Sat, 9 Mar 2024 23:00:44 -0500 Subject: [PATCH] Feature: Stop reporting metrics from disconnected sensors (temp, humidity, soil humidity) --- weather/weather.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/weather/weather.go b/weather/weather.go index c7d27d2..ff89658 100644 --- a/weather/weather.go +++ b/weather/weather.go @@ -88,13 +88,21 @@ func (p *Parser) Parse(values url.Values) { if values.Has(fmt.Sprintf("temp%df", i)) { updateGauge(p.temperature.WithLabelValues(p.name, iStr))(parseValue(fmt.Sprintf("temp%df", i))) updateGauge(p.battery.WithLabelValues(p.name, iStr))(parseValue("batt" + iStr)) + } else { + p.battery.DeleteLabelValues(p.name, iStr) + p.temperature.DeleteLabelValues(p.name, iStr) } if values.Has("soilhum" + iStr) { updateGauge(p.humidity.WithLabelValues(p.name, "soil"+iStr))(parseValue("soilhum" + iStr)) updateGauge(p.battery.WithLabelValues(p.name, "soil"+iStr))(parseValue("battsm" + iStr)) + } else { + p.humidity.DeleteLabelValues(p.name, "soil"+iStr) + p.battery.DeleteLabelValues(p.name, "soil"+iStr) } if values.Has("humidity" + iStr) { updateGauge(p.humidity.WithLabelValues(p.name, iStr))(parseValue("humidity" + iStr)) + } else { + p.humidity.DeleteLabelValues(p.name, iStr) } }