fix(cmd): turn on the led light when a sensor is selected

This commit is contained in:
Markus Pesch 2019-06-27 21:47:31 +02:00
parent 45763d7c9d
commit 180a284780
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 17 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import (
"os"
"github.com/go-flucky/flucky/pkg/logfile"
"github.com/go-flucky/flucky/pkg/rgbled"
"github.com/go-flucky/flucky/pkg/types/typeswitch"
"github.com/go-flucky/flucky/pkg/cli"
@ -35,8 +36,14 @@ var readHumidityCmd = &cobra.Command{
sensors = cnf.GetHumiditySensorsByName(args)
}
ctx := context.Background()
if len(sensors) == 0 {
return
}
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
rgbled.Run(rgbLEDs)
ctx := context.Background()
measuredValues, err := sensor.Read(ctx, sensors)
if err != nil {
log.Fatalln(err)
@ -44,7 +51,6 @@ var readHumidityCmd = &cobra.Command{
measuredValues = typeswitch.HumidityValues(measuredValues)
// print humidities on stdout
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
if logs {
@ -54,6 +60,8 @@ var readHumidityCmd = &cobra.Command{
log.Fatalln(err)
}
}
rgbled.Off(rgbLEDs)
},
}

View File

@ -18,7 +18,6 @@ import (
)
var logs bool
var temperatureUnit string
var readTemperatureCmd = &cobra.Command{
Use: "read",
@ -32,9 +31,6 @@ var readTemperatureCmd = &cobra.Command{
log.Fatalln(err)
}
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
rgbled.Run(rgbLEDs)
// fetch all temperature sensors or sensors by args
sensors := make([]sensor.Sensor, 0)
if len(args) == 0 {
@ -43,6 +39,13 @@ var readTemperatureCmd = &cobra.Command{
sensors = cnf.GetTemperatureSensorsByName(args)
}
if len(sensors) == 0 {
return
}
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
rgbled.Run(rgbLEDs)
ctx := context.Background()
measuredValues, err := sensor.Read(ctx, sensors)
if err != nil {
@ -73,5 +76,4 @@ func init() {
readTemperatureCmd.Flags().BoolVar(&logs, "logs", true, "Log temperature")
readTemperatureCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured with logged temperatures")
readTemperatureCmd.Flags().Float64VarP(&round, "round", "r", 0.25, "Round values. The value 0 deactivates the function")
readTemperatureCmd.Flags().StringVar(&temperatureUnit, "temperature-unit", "celsius", "Temperature unit")
}