forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevice.go
56 lines (45 loc) · 1.11 KB
/
device.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
49
50
51
52
53
54
55
56
package cmd
import (
"fmt"
"strings"
"github.com/evcc-io/evcc/util/config"
"github.com/evcc-io/evcc/util/templates"
"github.com/spf13/cobra"
)
// deviceCmd represents the device debug command
var deviceCmd = &cobra.Command{
Use: "device",
Short: "Query database-configured devices (debug only)",
Run: runDevice,
}
func init() {
rootCmd.AddCommand(deviceCmd)
}
func runDevice(cmd *cobra.Command, args []string) {
// load config
if err := loadConfigFile(&conf, !cmd.Flag(flagIgnoreDatabase).Changed); err != nil {
log.FATAL.Fatal(err)
}
// setup environment
if err := configureEnvironment(cmd, &conf); err != nil {
log.FATAL.Fatal(err)
}
for _, class := range []templates.Class{templates.Meter, templates.Charger, templates.Vehicle} {
devs, err := config.ConfigurationsByClass(class)
if err != nil {
log.FATAL.Fatal(err)
}
if len(devs) == 0 {
continue
}
fmt.Println(class)
fmt.Println(strings.Repeat("-", len(class.String())))
for _, d := range devs {
fmt.Printf("%d. %s\n", d.ID, d.Type)
fmt.Println(d.Value)
fmt.Println()
}
}
// wait for shutdown
<-shutdownDoneC()
}