forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice.go
67 lines (53 loc) · 1.27 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
57
58
59
60
61
62
63
64
65
66
67
package cmd
import (
"cmp"
"fmt"
"slices"
"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); 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)
details := d.Details
slices.SortFunc(details, func(i, j config.ConfigDetail) int {
return cmp.Compare(i.Key, j.Key)
})
for _, d := range details {
fmt.Printf("%s: %s\n", d.Key, d.Value)
}
fmt.Println()
}
}
// wait for shutdown
<-shutdownDoneC()
}