forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenergymeter.go
71 lines (54 loc) · 1.8 KB
/
energymeter.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
package shelly
import "github.com/evcc-io/evcc/api"
type EnergyMeter struct {
*Connection
}
func NewEnergyMeter(conn *Connection) *EnergyMeter {
res := &EnergyMeter{
Connection: conn,
}
return res
}
// CurrentPower implements the api.Meter interface
func (sh *EnergyMeter) CurrentPower() (float64, error) {
var res Gen2EmStatusResponse
if err := sh.Connection.execGen2Cmd("EM.GetStatus", false, &res); err != nil {
return 0, err
}
return res.TotalPower, nil
}
// TotalEnergy implements the api.Meter interface
func (sh *EnergyMeter) TotalEnergy() (float64, error) {
var res Gen2EmDataStatusResponse
if err := sh.Connection.execGen2Cmd("EMData.GetStatus", false, &res); err != nil {
return 0, err
}
return res.TotalEnergy / 1000, nil
}
var _ api.PhaseCurrents = (*EnergyMeter)(nil)
// Currents implements the api.PhaseCurrents interface
func (sh *EnergyMeter) Currents() (float64, float64, float64, error) {
var res Gen2EmStatusResponse
if err := sh.Connection.execGen2Cmd("EM.GetStatus", false, &res); err != nil {
return 0, 0, 0, err
}
return res.CurrentA, res.CurrentB, res.CurrentC, nil
}
var _ api.PhaseVoltages = (*EnergyMeter)(nil)
// Voltages implements the api.PhaseVoltages interface
func (sh *EnergyMeter) Voltages() (float64, float64, float64, error) {
var res Gen2EmStatusResponse
if err := sh.Connection.execGen2Cmd("EM.GetStatus", false, &res); err != nil {
return 0, 0, 0, err
}
return res.VoltageA, res.VoltageB, res.VoltageC, nil
}
var _ api.PhasePowers = (*EnergyMeter)(nil)
// Powers implements the api.PhasePowers interface
func (sh *EnergyMeter) Powers() (float64, float64, float64, error) {
var res Gen2EmStatusResponse
if err := sh.Connection.execGen2Cmd("EM.GetStatus", false, &res); err != nil {
return 0, 0, 0, err
}
return res.PowerA, res.PowerB, res.PowerC, nil
}