fix(cmd): turn on the led light when a sensor is selected
This commit is contained in:
parent
45763d7c9d
commit
180a284780
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/go-flucky/flucky/pkg/logfile"
|
"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/types/typeswitch"
|
||||||
|
|
||||||
"github.com/go-flucky/flucky/pkg/cli"
|
"github.com/go-flucky/flucky/pkg/cli"
|
||||||
@ -35,8 +36,14 @@ var readHumidityCmd = &cobra.Command{
|
|||||||
sensors = cnf.GetHumiditySensorsByName(args)
|
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)
|
measuredValues, err := sensor.Read(ctx, sensors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
@ -44,7 +51,6 @@ var readHumidityCmd = &cobra.Command{
|
|||||||
|
|
||||||
measuredValues = typeswitch.HumidityValues(measuredValues)
|
measuredValues = typeswitch.HumidityValues(measuredValues)
|
||||||
|
|
||||||
// print humidities on stdout
|
|
||||||
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
|
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
|
||||||
|
|
||||||
if logs {
|
if logs {
|
||||||
@ -54,6 +60,8 @@ var readHumidityCmd = &cobra.Command{
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rgbled.Off(rgbLEDs)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var logs bool
|
var logs bool
|
||||||
var temperatureUnit string
|
|
||||||
|
|
||||||
var readTemperatureCmd = &cobra.Command{
|
var readTemperatureCmd = &cobra.Command{
|
||||||
Use: "read",
|
Use: "read",
|
||||||
@ -32,9 +31,6 @@ var readTemperatureCmd = &cobra.Command{
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
|
|
||||||
rgbled.Run(rgbLEDs)
|
|
||||||
|
|
||||||
// fetch all temperature sensors or sensors by args
|
// fetch all temperature sensors or sensors by args
|
||||||
sensors := make([]sensor.Sensor, 0)
|
sensors := make([]sensor.Sensor, 0)
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
@ -43,6 +39,13 @@ var readTemperatureCmd = &cobra.Command{
|
|||||||
sensors = cnf.GetTemperatureSensorsByName(args)
|
sensors = cnf.GetTemperatureSensorsByName(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(sensors) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
|
||||||
|
rgbled.Run(rgbLEDs)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
measuredValues, err := sensor.Read(ctx, sensors)
|
measuredValues, err := sensor.Read(ctx, sensors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -73,5 +76,4 @@ func init() {
|
|||||||
readTemperatureCmd.Flags().BoolVar(&logs, "logs", true, "Log temperature")
|
readTemperatureCmd.Flags().BoolVar(&logs, "logs", true, "Log temperature")
|
||||||
readTemperatureCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured with logged temperatures")
|
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().Float64VarP(&round, "round", "r", 0.25, "Round values. The value 0 deactivates the function")
|
||||||
readTemperatureCmd.Flags().StringVar(&temperatureUnit, "temperature-unit", "celsius", "Temperature unit")
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user