2019-06-13 19:25:32 +00:00
|
|
|
package temperature
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-06-15 12:02:35 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2019-06-13 19:25:32 +00:00
|
|
|
|
2019-07-02 20:33:01 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/types"
|
|
|
|
|
2019-06-15 13:58:41 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/cli"
|
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
|
|
|
"github.com/go-flucky/flucky/pkg/logfile"
|
2019-06-30 12:34:13 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/rgbled"
|
2019-06-13 19:25:32 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var listTemperatureCmd = &cobra.Command{
|
|
|
|
Use: "list",
|
2019-07-02 20:54:58 +00:00
|
|
|
Short: "List temperature values from different or specified sensors by arguments",
|
2019-06-13 19:25:32 +00:00
|
|
|
Example: fmt.Sprintf("flucky temperature logs"),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
// read configuration
|
2019-08-19 10:24:08 +00:00
|
|
|
cnf, err := config.Read(*configFile)
|
2019-06-15 12:02:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2019-06-13 19:25:32 +00:00
|
|
|
|
2019-06-26 21:36:01 +00:00
|
|
|
logfile := logfile.New(cnf.Device.Logfile)
|
2019-06-19 17:18:01 +00:00
|
|
|
|
2019-06-30 12:34:13 +00:00
|
|
|
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
|
|
|
|
if err := rgbled.Logfile(rgbLEDs); err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-06-25 20:56:09 +00:00
|
|
|
measuredValues, err := logfile.Read()
|
2019-06-15 12:02:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-06-30 12:34:13 +00:00
|
|
|
if err := rgbled.Off(rgbLEDs); err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-07-02 20:33:01 +00:00
|
|
|
measuredValues = types.SelectMeasuredValues(types.MeasuredValueTypeTemperature, measuredValues)
|
2019-06-30 12:34:13 +00:00
|
|
|
|
2019-06-25 20:56:09 +00:00
|
|
|
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
|
2019-06-13 19:25:32 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
temperatureCmd.AddCommand(listTemperatureCmd)
|
|
|
|
}
|