Skip to content

Commit

Permalink
Add support for light sensors
Browse files Browse the repository at this point in the history
Query for currentAmbientLightLevel and expose that as a
lumen_per_square_meter time series
  • Loading branch information
daenney committed Jan 2, 2023
1 parent db83e31 commit a40f46f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions collectors/environmental.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type EnvironmentalCollector struct {
pm25 *prometheus.Desc
airQuality *prometheus.Desc
waterLevel *prometheus.Desc
lightLevel *prometheus.Desc

m *server.Manager
lat float64
Expand Down Expand Up @@ -113,6 +114,11 @@ func NewEnvironmentalCollector(m *server.Manager, lat, long float64) (prometheus
"Water Level",
[]string{"source"}, nil,
),
lightLevel: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "lumen_per_square_meter"),
"Light Level (Lux)",
[]string{"source"}, nil,
),
}, nil
}

Expand All @@ -132,6 +138,7 @@ func (c *EnvironmentalCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.pm25
ch <- c.airQuality
ch <- c.waterLevel
ch <- c.lightLevel
}

// Collect sends metric updates into the channel
Expand Down Expand Up @@ -273,6 +280,19 @@ func (c *EnvironmentalCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(c.waterLevel,
prometheus.GaugeValue, vf, s.Info().Topic)
}
if ft := s.Feature("currentAmbientLightLevel"); ft.Exists() {
v := ft.Value()
if v == "" {
continue
}
vf, err := toFloat(v)
if err != nil {
log.Print(err.Error())
continue
}
ch <- prometheus.MustNewConstMetric(c.lightLevel,
prometheus.GaugeValue, vf, s.Info().Topic)
}
}

for dev, temp := range temperature {
Expand Down

0 comments on commit a40f46f

Please sign in to comment.