forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite_circuits.go
38 lines (30 loc) · 897 Bytes
/
site_circuits.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
package core
import (
"github.com/evcc-io/evcc/core/keys"
"github.com/evcc-io/evcc/util/config"
"github.com/samber/lo"
)
type circuitStruct struct {
Power float64 `json:"power"`
Current *float64 `json:"current,omitempty"`
MaxPower float64 `json:"maxPower,omitempty"`
MaxCurrent float64 `json:"maxCurrent,omitempty"`
}
// publishCircuits returns a list of circuit titles
func (site *Site) publishCircuits() {
cc := config.Circuits().Devices()
res := make(map[string]circuitStruct, len(cc))
for _, c := range cc {
instance := c.Instance()
data := circuitStruct{
Power: instance.GetChargePower(),
MaxPower: instance.GetMaxPower(),
MaxCurrent: instance.GetMaxCurrent(),
}
if instance.GetMaxCurrent() > 0 {
data.Current = lo.EmptyableToPtr(instance.GetMaxPhaseCurrent())
}
res[c.Config().Name] = data
}
site.publish(keys.Circuits, res)
}