diff --git a/api/api.go b/api/api.go index 8879c4df6..a6e4ab886 100644 --- a/api/api.go +++ b/api/api.go @@ -37,6 +37,11 @@ type MeterEnergy interface { TotalEnergy() (float64, error) } +// MeterCurrent is able to provide per-line current A +type MeterCurrent interface { + Currents() (float64, float64, float64, error) +} + // Charger is able to provide current charging status and to enable/disabler charging type Charger interface { Status() (ChargeStatus, error) diff --git a/charger/go-e.go b/charger/go-e.go index 6f2c7fe03..c9ee37157 100644 --- a/charger/go-e.go +++ b/charger/go-e.go @@ -139,3 +139,13 @@ func (c *GoE) ChargedEnergy() (float64, error) { energy := float64(status.Dws) / 3.6e6 return energy, err } + +// Currents implements the MeterCurrent interface +func (c *GoE) Currents() (float64, float64, float64, error) { + var status goeStatusResponse + _, err := c.GetJSON(c.apiURL(goeStatus), &status) + if len(status.Nrg) == 16 { + return float64(status.Nrg[4]) / 10, float64(status.Nrg[5]) / 10, float64(status.Nrg[6]) / 10, nil + } + return 0, 0, 0, err +} diff --git a/cmd/dump.go b/cmd/dump.go index f84ea8bdb..548c4f4a0 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -25,6 +25,14 @@ func dumpAPIs(v interface{}) { } } + if v, ok := v.(api.MeterCurrent); ok { + if i1, i2, i3, err := v.Currents(); err != nil { + fmt.Printf("Current L1..L3: %v\n", err) + } else { + fmt.Printf("Current L1..L3: %.1fA %.1fA %.1fA\n", i1, i2, i3) + } + } + if v, ok := v.(api.ChargeRater); ok { if energy, err := v.ChargedEnergy(); err != nil { fmt.Printf("Charged: %v\n", err)