2018-11-20 21:55:06 +00:00
|
|
|
package sensor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2018-11-21 19:48:10 +00:00
|
|
|
|
|
|
|
"git.cryptic.systems/fh-trier/go-flucky/pkg/types"
|
2018-11-20 21:55:06 +00:00
|
|
|
)
|
|
|
|
|
2018-11-21 19:48:10 +00:00
|
|
|
// Exists returns a boolean if the sensor exists
|
|
|
|
func Exists(wirePath, sensorID string) bool {
|
2018-11-20 21:55:06 +00:00
|
|
|
sensorPath := filepath.Join(wirePath, sensorID)
|
|
|
|
if _, err := os.Stat(sensorPath); os.IsNotExist(err) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2018-11-21 19:48:10 +00:00
|
|
|
|
|
|
|
// IsRedundant returns a boolean if the sensorID is in the array
|
|
|
|
func IsRedundant(sensorID string, sensors []*types.WireSensor) bool {
|
|
|
|
for _, sensor := range sensors {
|
|
|
|
if sensor.ID == sensorID {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|