PKGBUILD/cmd/sensor/temperature/add.go

50 lines
1.1 KiB
Go
Raw Normal View History

package temperature
import (
2018-11-21 19:48:10 +00:00
"fmt"
"log"
2018-11-21 19:48:10 +00:00
temperatureSensor "git.cryptic.systems/fh-trier/go-flucky/pkg/sensor/temperature"
"git.cryptic.systems/fh-trier/go-flucky/pkg/types"
"github.com/spf13/cobra"
)
2018-11-21 19:48:10 +00:00
var sensorType string
var addTemperatureSensorCmd = &cobra.Command{
Use: "add",
Short: "Add Temperature Sensor",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
2018-11-21 19:48:10 +00:00
t, err := matchSensorTyp(sensorType)
if err != nil {
log.Fatal(err)
}
2018-11-21 19:48:10 +00:00
// DS18B20
if t == types.SENSOR_DS18B20 {
if err := temperatureSensor.AddDS18B20(args[0], sensorName, configDir, wirePath); err != nil {
log.Fatal(err)
}
}
},
}
func init() {
temperatureSensorCmd.AddCommand(addTemperatureSensorCmd)
2018-11-21 19:48:10 +00:00
addTemperatureSensorCmd.Flags().StringVarP(&sensorType, "type", "t", "DS18B20", "Sensor Types: DS18B20, DHT11")
}
func matchSensorTyp(sensorType string) (types.SensorType, error) {
switch sensorType {
case "DS18B20":
return types.SENSOR_DS18B20, nil
case "DHT11":
return types.SENSOR_DHT11, nil
}
return "", fmt.Errorf("Can not match %v with a sensor type", sensorType)
}