diff --git a/cmd/cmd.go b/cmd/cmd.go index ddc1bf3..e6ee7ad 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -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) diff --git a/cmd/humidity/read.go b/cmd/humidity/read.go index e43d531..de2ca56 100644 --- a/cmd/humidity/read.go +++ b/cmd/humidity/read.go @@ -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)