fix(pkg/sensor): reduce interface functions for better error handling
This commit is contained in:
@ -6,12 +6,12 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/go-flucky/flucky/pkg/storage"
|
||||
"github.com/go-flucky/flucky/pkg/types"
|
||||
|
||||
"github.com/go-flucky/flucky/pkg/cli"
|
||||
"github.com/go-flucky/flucky/pkg/config"
|
||||
"github.com/go-flucky/flucky/pkg/rgbled"
|
||||
"github.com/go-flucky/flucky/pkg/sensor"
|
||||
"github.com/go-flucky/flucky/pkg/storage"
|
||||
"github.com/go-flucky/flucky/pkg/types"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -39,36 +39,33 @@ var readTemperatureCmd = &cobra.Command{
|
||||
log.Fatalln("No sensors found, specified or configured")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
measuredValues, err := sensor.Read(ctx, sensors)
|
||||
if err != nil {
|
||||
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
|
||||
if err := rgbled.Run(rgbLEDs); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
storage.Round(measuredValues, round)
|
||||
measuredValues, err := sensor.Read(sensors, types.MeasuredValueTypeTemperature)
|
||||
if err := rgbled.Run(rgbLEDs); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
measuredValues = types.SelectMeasuredValues(types.MeasuredValueTypeTemperature, measuredValues)
|
||||
|
||||
// print temperatures on stdout
|
||||
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
|
||||
|
||||
// Save the new measured values, if desired
|
||||
if logs {
|
||||
|
||||
if compression {
|
||||
measuredValues = storage.Compression(measuredValues)
|
||||
}
|
||||
|
||||
storageEndpoint, err := cnf.GetStorageEndpointURL()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
err = storage.Write(ctx, measuredValues, storageEndpoint)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
rgbled.Off(rgbLEDs)
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user