forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeter.go
48 lines (39 loc) · 970 Bytes
/
meter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cmd
import (
"github.com/andig/evcc/api"
"github.com/andig/evcc/server"
"github.com/andig/evcc/util"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// meterCmd represents the meter command
var meterCmd = &cobra.Command{
Use: "meter [name]",
Short: "Query configured meters",
Run: runMeter,
}
func init() {
rootCmd.AddCommand(meterCmd)
}
func runMeter(cmd *cobra.Command, args []string) {
util.LogLevel(viper.GetString("log"), viper.GetStringMapString("levels"))
log.INFO.Printf("evcc %s (%s)", server.Version, server.Commit)
// load config
conf := loadConfigFile(cfgFile)
// setup mqtt
if conf.Mqtt.Broker != "" {
configureMQTT(conf.Mqtt)
}
if err := cp.configureMeters(conf); err != nil {
log.FATAL.Fatal(err)
}
meters := cp.meters
if len(args) == 1 {
arg := args[0]
meters = map[string]api.Meter{arg: cp.Meter(arg)}
}
d := dumper{len: len(meters)}
for name, v := range meters {
d.DumpWithHeader(name, v)
}
}