fix(cmd/temperature/read): turn on rgbleds while execute subcommand

This commit is contained in:
Markus Pesch 2019-06-24 23:08:23 +02:00
parent 5f53207f0a
commit 30603e348c
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982

View File

@ -5,6 +5,8 @@ import (
"log"
"os"
"github.com/go-flucky/flucky/pkg/rgbled"
"github.com/go-flucky/flucky/pkg/cli"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/logfile"
@ -27,6 +29,9 @@ var readTemperatureCmd = &cobra.Command{
log.Fatalln(err)
}
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
rgbled.Run(rgbLEDs)
// fetch all temperature sensors or sensors by args
temperatureSensors := make([]sensor.TemperatureSensor, 0)
if len(args) == 0 {
@ -37,11 +42,13 @@ var readTemperatureCmd = &cobra.Command{
measurementUnit, err := sensor.SelectTemperatureMeasurementUnit(temperatureUnit)
if err != nil {
rgbled.Error(rgbLEDs)
log.Fatalf("Can not parse temperature unit: %v", temperatureUnit)
}
temperatures, err := sensor.ReadTemperatures(temperatureSensors, measurementUnit, round)
if err != nil {
rgbled.Error(rgbLEDs)
log.Fatalln(err)
}
@ -52,9 +59,12 @@ var readTemperatureCmd = &cobra.Command{
temperatureLogfile := logfile.New(cnf.Device.TemperatureLogfile)
err := logfile.AppendTemperatures(temperatureLogfile, compression, temperatures)
if err != nil {
rgbled.Error(rgbLEDs)
log.Fatalln(err)
}
}
rgbled.Off(rgbLEDs)
},
}