fix(pkg/config): get temperature or humidity sensors

This commit is contained in:
Markus Pesch 2019-06-27 18:43:16 +02:00
parent 8005248262
commit 4975ce21fa
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982

View File

@ -226,25 +226,27 @@ func (c *Configuration) EnableSensor(name string) error {
// GetHumiditySensors returns a list of humidity sensors // GetHumiditySensors returns a list of humidity sensors
func (c *Configuration) GetHumiditySensors(option Option) []sensor.Sensor { func (c *Configuration) GetHumiditySensors(option Option) []sensor.Sensor {
humiditySensors := c.getHumiditySensors() sensors := c.getHumiditySensors()
cachedSensors := make([]*types.Sensor, 0)
switch option { switch option {
case ENABLED: case ENABLED:
for i, humiditySensor := range humiditySensors { for _, sensor := range sensors {
if !humiditySensor.SensorEnabled { if sensor.SensorEnabled {
humiditySensors = append(humiditySensors[:i], humiditySensors[i+1:]...) cachedSensors = append(cachedSensors, sensor)
} }
} }
return c.convertSensors(humiditySensors) return c.convertSensors(cachedSensors)
case DISABLED: case DISABLED:
for i, humiditySensor := range humiditySensors { for _, sensor := range sensors {
if humiditySensor.SensorEnabled { if !sensor.SensorEnabled {
humiditySensors = append(humiditySensors[:i], humiditySensors[i+1:]...) cachedSensors = append(cachedSensors, sensor)
} }
} }
return c.convertSensors(humiditySensors) return c.convertSensors(cachedSensors)
default: default:
return c.convertSensors(humiditySensors) return c.convertSensors(cachedSensors)
} }
} }
@ -321,25 +323,27 @@ func (c *Configuration) GetRGBLEDsByName(names []string) []rgbled.RGBLED {
// GetTemperatureSensors returns a list of temperature sensors // GetTemperatureSensors returns a list of temperature sensors
func (c *Configuration) GetTemperatureSensors(option Option) []sensor.Sensor { func (c *Configuration) GetTemperatureSensors(option Option) []sensor.Sensor {
temperatureSensors := c.getTemperatureSensors() sensors := c.getTemperatureSensors()
cachedSensors := make([]*types.Sensor, 0)
switch option { switch option {
case ENABLED: case ENABLED:
for i, temperatureSensor := range temperatureSensors { for _, sensor := range sensors {
if !temperatureSensor.SensorEnabled { if sensor.SensorEnabled {
temperatureSensors = append(temperatureSensors[:i], temperatureSensors[i+1:]...) cachedSensors = append(cachedSensors, sensor)
} }
} }
return c.convertSensors(temperatureSensors) return c.convertSensors(cachedSensors)
case DISABLED: case DISABLED:
for i, temperatureSensor := range temperatureSensors { for _, sensor := range sensors {
if temperatureSensor.SensorEnabled { if !sensor.SensorEnabled {
temperatureSensors = append(temperatureSensors[:i], temperatureSensors[i+1:]...) cachedSensors = append(cachedSensors, sensor)
} }
} }
return c.convertSensors(temperatureSensors) return c.convertSensors(cachedSensors)
default: default:
return c.convertSensors(temperatureSensors) return c.convertSensors(cachedSensors)
} }
} }