From 45763d7c9dd11bccbf264a5fc479727bc46974ec Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Thu, 27 Jun 2019 20:33:40 +0200 Subject: [PATCH] fix(pkg/daemon): use all enables sensors instead of only temperature sensors --- pkg/config/flucky.go | 24 ++++++++++++++++++++++++ pkg/daemon/daemon.go | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/config/flucky.go b/pkg/config/flucky.go index bdf782c..dba3482 100644 --- a/pkg/config/flucky.go +++ b/pkg/config/flucky.go @@ -321,6 +321,30 @@ func (c *Configuration) GetRGBLEDsByName(names []string) []rgbled.RGBLED { return c.convertRGBLEDs(rgbLEDs) } +// GetSensors returns a list of humidity sensors +func (c *Configuration) GetSensors(option Option) []sensor.Sensor { + cachedSensors := make([]*types.Sensor, 0) + + switch option { + case ENABLED: + for _, sensor := range c.Sensors { + if sensor.SensorEnabled { + cachedSensors = append(cachedSensors, sensor) + } + } + return c.convertSensors(cachedSensors) + case DISABLED: + for _, sensor := range c.Sensors { + if !sensor.SensorEnabled { + cachedSensors = append(cachedSensors, sensor) + } + } + return c.convertSensors(cachedSensors) + default: + return c.convertSensors(cachedSensors) + } +} + // GetTemperatureSensors returns a list of temperature sensors func (c *Configuration) GetTemperatureSensors(option Option) []sensor.Sensor { sensors := c.getTemperatureSensors() diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index 93e374b..824f166 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -37,7 +37,7 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress measuredValuesCache := make([]types.MeasuredValue, 0) - go sensor.ReadContinuously(childContext, cnf.GetTemperatureSensors(config.ENABLED), measuredValuesChannel, errorChannel) + go sensor.ReadContinuously(childContext, cnf.GetSensors(config.ENABLED), measuredValuesChannel, errorChannel) rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)