PKGBUILD/cmd/humidity/read.go

58 lines
1.5 KiB
Go
Raw Normal View History

package humidity
import (
"log"
"os"
"github.com/go-flucky/flucky/pkg/cli"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/sensor"
"github.com/spf13/cobra"
)
var logs bool
var readHumidityCmd = &cobra.Command{
Use: "read",
Short: "read humidity from sensor",
Run: func(cmd *cobra.Command, args []string) {
// read configuration
cnf, err := config.Read(configFile)
if err != nil {
log.Fatalln(err)
}
// fetch all temperature sensors or sensors by args
humiditySensors := make([]sensor.HumiditySensor, 0)
if len(args) == 0 {
humiditySensors = cnf.GetHumiditySensors(config.ENABLED)
} else {
humiditySensors = cnf.GetHumiditySensorsByName(args)
}
humidities, err := sensor.ReadHumidities(humiditySensors, round)
if err != nil {
log.Fatalln(err)
}
// print humidities on stdout
cli.PrintHumidities(humidities, cnf, os.Stdout)
// if logs {
// humiditiyLogfile := logfile.New(cnf.Device.HumidityLogfile)
// err := logfile.AppendTemperatures(humiditiyLogfile, compression, humidities)
// if err != nil {
// log.Fatalln(err)
// }
// }
},
}
func init() {
humidityCmd.AddCommand(readHumidityCmd)
readHumidityCmd.Flags().BoolVar(&logs, "logs", true, "Log temperature")
readHumidityCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured with logged temperatures")
readHumidityCmd.Flags().Float64VarP(&round, "round", "r", 0.25, "Round values. The value 0 deactivates the function")
}