From 7395777e4906a89cdad4c349e44d90a3aff8e00f Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 12 Jan 2023 16:12:46 +0100 Subject: [PATCH] Go-E: detect phase configuration from voltages (#5764) --- charger/go-e.go | 14 ++++++++++++++ charger/go-e/api.go | 1 + charger/go-e/types.go | 7 +++++++ charger/go-e/types2.go | 8 ++++++++ 4 files changed, 30 insertions(+) diff --git a/charger/go-e.go b/charger/go-e.go index 9ae539c49..3f8497fb9 100644 --- a/charger/go-e.go +++ b/charger/go-e.go @@ -176,6 +176,20 @@ func (c *GoE) Currents() (float64, float64, float64, error) { return i1, i2, i3, err } +var _ api.PhaseVoltages = (*GoE)(nil) + +// Voltages implements the api.PhaseVoltages interface +func (c *GoE) Voltages() (float64, float64, float64, error) { + resp, err := c.api.Status() + if err != nil { + return 0, 0, 0, err + } + + u1, u2, u3 := resp.Voltages() + + return u1, u2, u3, err +} + var _ api.Identifier = (*GoE)(nil) // Identify implements the api.Identifier interface diff --git a/charger/go-e/api.go b/charger/go-e/api.go index c6fa5e9b4..ea012ab75 100644 --- a/charger/go-e/api.go +++ b/charger/go-e/api.go @@ -20,6 +20,7 @@ type Response interface { ChargedEnergy() float64 TotalEnergy() float64 Currents() (float64, float64, float64) + Voltages() (float64, float64, float64) Identify() string } diff --git a/charger/go-e/types.go b/charger/go-e/types.go index fb5f6bdde..a7dc01c16 100644 --- a/charger/go-e/types.go +++ b/charger/go-e/types.go @@ -63,6 +63,13 @@ func (g *StatusResponse) Currents() (float64, float64, float64) { return 0, 0, 0 } +func (g *StatusResponse) Voltages() (float64, float64, float64) { + if len(g.Nrg) == 16 { + return g.Nrg[0], g.Nrg[1], g.Nrg[2] + } + return 0, 0, 0 +} + func (g *StatusResponse) Identify() string { switch g.Uby { case 1: diff --git a/charger/go-e/types2.go b/charger/go-e/types2.go index 6871040ea..4b0d12c89 100644 --- a/charger/go-e/types2.go +++ b/charger/go-e/types2.go @@ -56,6 +56,14 @@ func (g *StatusResponse2) Currents() (float64, float64, float64) { return 0, 0, 0 } +func (g *StatusResponse2) Voltages() (float64, float64, float64) { + if len(g.Nrg) == 16 { + return g.Nrg[0], g.Nrg[1], g.Nrg[2] + } + + return 0, 0, 0 +} + func (g *StatusResponse2) Identify() string { if g.Trx > 0 { return g.Cards[g.Trx-1].Name