forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyze.go
98 lines (81 loc) · 1.77 KB
/
analyze.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package detect
import "github.com/evcc-io/evcc/detect/tasks"
type Criteria map[string]interface{}
func filter(list []tasks.Result, criteria []Criteria) (match []tasks.Result) {
for _, res := range list {
for _, criterium := range criteria {
ok := true
for matchKey, matchVal := range criterium {
if foundVal, found := res.Attributes[matchKey]; !found || foundVal != matchVal {
ok = false
break
}
}
if ok {
match = append(match, res)
}
}
}
return match
}
type TypeSummary struct {
Results []tasks.Result
Found, Unique bool
}
type Summary struct {
Charger, Grid, PV, Charge, Battery, Meter TypeSummary
}
func summarize(res []tasks.Result) TypeSummary {
return TypeSummary{
Results: res,
Found: len(res) > 0,
Unique: len(res) == 1,
}
}
const (
tid = "task.id"
smaHttp = "details.http"
)
func Consolidate(res []tasks.Result) Summary {
grid := filter(res, []Criteria{
{tid: taskOpenwb},
{tid: taskSMA, smaHttp: false},
{tid: taskE3DC},
{tid: taskSonnen},
})
pv := filter(res, []Criteria{
{tid: taskOpenwb},
{tid: taskInverter},
})
battery := filter(res, []Criteria{
{tid: taskOpenwb},
{tid: taskE3DC},
{tid: taskSonnen},
{tid: taskBattery},
})
charger := filter(res, []Criteria{
{tid: taskOpenwb},
{tid: taskWallbe},
{tid: taskPhoenixEMEth},
{tid: taskPhoenixEVEth},
{tid: taskEVSEWifi},
{tid: taskGoE},
{tid: taskKEBA},
})
charge := filter(res, []Criteria{
{tid: taskOpenwb},
{tid: taskKEBA},
})
meter := filter(res, []Criteria{
{tid: taskSMA, smaHttp: true},
{tid: taskMeter},
})
return Summary{
Grid: summarize(grid),
PV: summarize(pv),
Battery: summarize(battery),
Charger: summarize(charger),
Charge: summarize(charge),
Meter: summarize(meter),
}
}