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
func (c *Configuration) GetHumiditySensors(option Option) []sensor.Sensor {
humiditySensors := c.getHumiditySensors()
sensors := c.getHumiditySensors()
cachedSensors := make([]*types.Sensor, 0)
switch option {
case ENABLED:
for i, humiditySensor := range humiditySensors {
if !humiditySensor.SensorEnabled {
humiditySensors = append(humiditySensors[:i], humiditySensors[i+1:]...)
for _, sensor := range sensors {
if sensor.SensorEnabled {
cachedSensors = append(cachedSensors, sensor)
}
}
return c.convertSensors(humiditySensors)
return c.convertSensors(cachedSensors)
case DISABLED:
for i, humiditySensor := range humiditySensors {
if humiditySensor.SensorEnabled {
humiditySensors = append(humiditySensors[:i], humiditySensors[i+1:]...)
for _, sensor := range sensors {
if !sensor.SensorEnabled {
cachedSensors = append(cachedSensors, sensor)
}
}
return c.convertSensors(humiditySensors)
return c.convertSensors(cachedSensors)
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
func (c *Configuration) GetTemperatureSensors(option Option) []sensor.Sensor {
temperatureSensors := c.getTemperatureSensors()
sensors := c.getTemperatureSensors()
cachedSensors := make([]*types.Sensor, 0)
switch option {
case ENABLED:
for i, temperatureSensor := range temperatureSensors {
if !temperatureSensor.SensorEnabled {
temperatureSensors = append(temperatureSensors[:i], temperatureSensors[i+1:]...)
for _, sensor := range sensors {
if sensor.SensorEnabled {
cachedSensors = append(cachedSensors, sensor)
}
}
return c.convertSensors(temperatureSensors)
return c.convertSensors(cachedSensors)
case DISABLED:
for i, temperatureSensor := range temperatureSensors {
if temperatureSensor.SensorEnabled {
temperatureSensors = append(temperatureSensors[:i], temperatureSensors[i+1:]...)
for _, sensor := range sensors {
if !sensor.SensorEnabled {
cachedSensors = append(cachedSensors, sensor)
}
}
return c.convertSensors(temperatureSensors)
return c.convertSensors(cachedSensors)
default:
return c.convertSensors(temperatureSensors)
return c.convertSensors(cachedSensors)
}
}