fix(pkg/config): option to select all, enable or disable temperature sensors
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
|
||||
"fmt"
|
||||
|
||||
"time"
|
||||
@ -119,15 +118,35 @@ func (c *Configuration) EnableSensor(name string) error {
|
||||
}
|
||||
|
||||
// GetHumiditySensors returns a list of humidity sensors
|
||||
func (c *Configuration) GetHumiditySensors() []sensor.HumiditySensor{
|
||||
humiditySensors, _ := c.splitSensors()
|
||||
return humiditySensors
|
||||
func (c *Configuration) GetHumiditySensors() []sensor.HumiditySensor {
|
||||
humiditySensors, _ := c.splitSensors()
|
||||
return humiditySensors
|
||||
}
|
||||
|
||||
// GetTemperatureSensors returns a list of humidity sensors
|
||||
func (c *Configuration) GetTemperatureSensors() []sensor.TemperatureSensor{
|
||||
_, temperatureSensors := c.splitSensors()
|
||||
return temperatureSensors
|
||||
func (c *Configuration) GetTemperatureSensors(option Option) []sensor.TemperatureSensor {
|
||||
_, temperatureSensors := c.splitSensors()
|
||||
|
||||
switch option {
|
||||
case ENABLED:
|
||||
for i, temperatureSensor := range temperatureSensors {
|
||||
if !temperatureSensor.GetEnabled() {
|
||||
temperatureSensors = append(temperatureSensors[:i], temperatureSensors[i+1:]...)
|
||||
}
|
||||
}
|
||||
return temperatureSensors
|
||||
case DISABLED:
|
||||
for i, temperatureSensor := range temperatureSensors {
|
||||
if temperatureSensor.GetEnabled() {
|
||||
temperatureSensors = append(temperatureSensors[:i], temperatureSensors[i+1:]...)
|
||||
}
|
||||
}
|
||||
return temperatureSensors
|
||||
case ALL:
|
||||
return temperatureSensors
|
||||
default:
|
||||
return temperatureSensors
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveSensor deletes a sensor by its name or its unique UUID
|
||||
|
14
pkg/config/option.go
Normal file
14
pkg/config/option.go
Normal file
@ -0,0 +1,14 @@
|
||||
package config
|
||||
|
||||
type Option int
|
||||
|
||||
const (
|
||||
// ALL specified enabled and disabled items
|
||||
ALL Option = iota + 1
|
||||
|
||||
// ENABLED items
|
||||
ENABLED
|
||||
|
||||
// DISABLED items
|
||||
DISABLED
|
||||
)
|
Reference in New Issue
Block a user