fix(cmd/humidity): enabled humidity read command - use measured value interface instead humidity struct

This commit is contained in:
Markus Pesch 2019-06-27 18:49:04 +02:00
parent 4680841684
commit 6469c0dd6c
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 14 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/go-flucky/flucky/cmd/daemon"
"github.com/go-flucky/flucky/cmd/humidity"
"github.com/go-flucky/flucky/cmd/rgbled"
"github.com/go-flucky/flucky/cmd/sensor"
"github.com/go-flucky/flucky/cmd/temperature"
@ -56,7 +57,7 @@ func Execute(version string) {
rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/flucky/config.json", "Config file")
daemon.InitCmd(rootCmd, configFile)
//humidity.InitCmd(rootCmd, configFile)
humidity.InitCmd(rootCmd, configFile)
rgbled.InitCmd(rootCmd, configFile)
sensor.InitCmd(rootCmd, configFile)
temperature.InitCmd(rootCmd, configFile)

View File

@ -1,9 +1,12 @@
package humidity
import (
"context"
"log"
"os"
"github.com/go-flucky/flucky/pkg/types/typeswitch"
"github.com/go-flucky/flucky/pkg/cli"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/sensor"
@ -24,20 +27,24 @@ var readHumidityCmd = &cobra.Command{
}
// fetch all temperature sensors or sensors by args
humiditySensors := make([]sensor.HumiditySensor, 0)
sensors := make([]sensor.Sensor, 0)
if len(args) == 0 {
humiditySensors = cnf.GetHumiditySensors(config.ENABLED)
sensors = cnf.GetHumiditySensors(config.ENABLED)
} else {
humiditySensors = cnf.GetHumiditySensorsByName(args)
sensors = cnf.GetHumiditySensorsByName(args)
}
humidities, err := sensor.ReadHumidities(humiditySensors, round)
ctx := context.Background()
measuredValues, err := sensor.Read(ctx, sensors)
if err != nil {
log.Fatalln(err)
}
measuredValues = typeswitch.HumidityValues(measuredValues)
// print humidities on stdout
cli.PrintHumidities(humidities, cnf, os.Stdout)
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
// if logs {
// humiditiyLogfile := logfile.New(cnf.Device.HumidityLogfile)