feat(cli/humidity): add new subcommand to read humidity values
This commit is contained in:
@ -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"
|
||||
@ -57,6 +58,7 @@ func Execute(version string) {
|
||||
rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/flucky/config.json", "Config file")
|
||||
|
||||
daemon.InitCmd(rootCmd, configFile)
|
||||
humidity.InitCmd(rootCmd, configFile)
|
||||
rgbled.InitCmd(rootCmd, configFile)
|
||||
sensor.InitCmd(rootCmd, configFile)
|
||||
temperature.InitCmd(rootCmd, configFile)
|
||||
|
@ -1,25 +0,0 @@
|
||||
package humidity
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var follow, push bool
|
||||
|
||||
var getHumidityCmd = &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "get humidity from sensor",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// if err := humidity.Get(); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
humidityCmd.AddCommand(getHumidityCmd)
|
||||
// getTemperatureCmd.Flags().BoolVarP(&follow, "follow", "f", false, "Follow output")
|
||||
// getTemperatureCmd.Flags().BoolVarP(&push, "push", "p", false, "Push to remote server")
|
||||
}
|
@ -4,7 +4,9 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var compression bool
|
||||
var configFile string
|
||||
var round float64
|
||||
|
||||
var humidityCmd = &cobra.Command{
|
||||
Use: "humidity",
|
||||
|
57
cmd/humidity/read.go
Normal file
57
cmd/humidity/read.go
Normal file
@ -0,0 +1,57 @@
|
||||
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")
|
||||
}
|
Reference in New Issue
Block a user