From 65c11a7d126aa4709a010e9c36d6ede9714617cd Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 10 Nov 2022 11:47:04 +0100 Subject: [PATCH] Go-E: fix session energy reset on disconnect (BC) (#5119) --- charger/go-e.go | 13 +++++-------- charger/go-e_test.go | 2 ++ core/loadpoint.go | 6 +++++- templates/definition/charger/go-e-v3.yaml | 5 +++-- templates/definition/charger/go-e.yaml | 1 + templates/docs/charger/go-e-v3_0.yaml | 3 ++- templates/docs/charger/go-e_0.yaml | 1 + 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/charger/go-e.go b/charger/go-e.go index 2844d8644..d791cbb2c 100644 --- a/charger/go-e.go +++ b/charger/go-e.go @@ -77,15 +77,12 @@ func NewGoE(uri, token string, cache time.Duration) (api.Charger, error) { c.api = goe.NewLocal(log, util.DefaultScheme(uri, "http"), cache) } - if c.api.IsV2() { - var phases func(int) error - if sponsor.IsAuthorized() { - phases = c.phases1p3p - } else { - log.WARN.Println("automatic 1p3p phase switching requires sponsor token") - } + if !sponsor.IsAuthorized() { + return nil, api.ErrSponsorRequired + } - return decorateGoE(c, c.totalEnergy, phases), nil + if c.api.IsV2() { + return decorateGoE(c, c.totalEnergy, c.phases1p3p), nil } return c, nil diff --git a/charger/go-e_test.go b/charger/go-e_test.go index 4c8a7e6f5..1b1a4de55 100644 --- a/charger/go-e_test.go +++ b/charger/go-e_test.go @@ -36,6 +36,8 @@ func TestGoEV1(t *testing.T) { h := &handler{} srv := httptest.NewServer(h) + sponsor.Subject = "foo" + wb, err := NewGoE(srv.URL, "", 0) if err != nil { t.Error(err) diff --git a/core/loadpoint.go b/core/loadpoint.go index 1de19fdba..7b7bd68a9 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -1523,7 +1523,11 @@ func (lp *LoadPoint) updateChargeCurrents() { // publish charged energy and duration func (lp *LoadPoint) publishChargeProgress() { if f, err := lp.chargeRater.ChargedEnergy(); err == nil { - lp.setChargedEnergy(1e3 * f) // convert to Wh + // workaround for Go-E resetting during disconnect, see + // https://github.com/evcc-io/evcc/issues/5092 + if f > 0 { + lp.setChargedEnergy(1e3 * f) // convert to Wh + } } else { lp.log.ERROR.Printf("charge rater: %v", err) } diff --git a/templates/definition/charger/go-e-v3.yaml b/templates/definition/charger/go-e-v3.yaml index a3b8e908f..fc2689100 100644 --- a/templates/definition/charger/go-e-v3.yaml +++ b/templates/definition/charger/go-e-v3.yaml @@ -9,12 +9,13 @@ requirements: de: | Benötigt mindestens Firmware 052.1 oder neuer. - Für 1P/3P-Phasenumschaltung muss die HTTP API v2 im Charger aktiviert sein und es wird ein Sponsortoken benötigt. 💚 + Für 1P/3P-Phasenumschaltung muss die HTTP API v2 im Charger aktiviert sein. en: | Requires firmware 052.1 or later. - For 1P/3P-Phase switching the HTTP API v2 in the charger setup needs to be activated and a sponsor token is required. 💚 + For 1P/3P-Phase switching the HTTP API v2 in the charger setup needs to be activated. uri: https://docs.evcc.io/docs/devices/chargers#go-echarger + evcc: ["sponsorship"] params: - name: host render: | diff --git a/templates/definition/charger/go-e.yaml b/templates/definition/charger/go-e.yaml index 46e845bc8..63695724f 100644 --- a/templates/definition/charger/go-e.yaml +++ b/templates/definition/charger/go-e.yaml @@ -8,6 +8,7 @@ requirements: description: en: Requires firmware 040.0 or later. de: Benötigt mindestens Firmware 040.0 oder neuer. + evcc: ["sponsorship"] params: - name: host render: | diff --git a/templates/docs/charger/go-e-v3_0.yaml b/templates/docs/charger/go-e-v3_0.yaml index bef189d8f..98c111bc9 100644 --- a/templates/docs/charger/go-e-v3_0.yaml +++ b/templates/docs/charger/go-e-v3_0.yaml @@ -2,10 +2,11 @@ product: brand: go-eCharger description: HOME+, HOMEfix (V3) capabilities: ["1p3p", "rfid"] +requirements: ["sponsorship"] description: | Benötigt mindestens Firmware 052.1 oder neuer. - Für 1P/3P-Phasenumschaltung muss die HTTP API v2 im Charger aktiviert sein und es wird ein Sponsortoken benötigt. 💚 + Für 1P/3P-Phasenumschaltung muss die HTTP API v2 im Charger aktiviert sein. render: - default: | diff --git a/templates/docs/charger/go-e_0.yaml b/templates/docs/charger/go-e_0.yaml index 8dbc19d82..500110bbd 100644 --- a/templates/docs/charger/go-e_0.yaml +++ b/templates/docs/charger/go-e_0.yaml @@ -2,6 +2,7 @@ product: brand: go-eCharger description: HOME+, HOMEfix, Pro capabilities: ["rfid"] +requirements: ["sponsorship"] description: | Benötigt mindestens Firmware 040.0 oder neuer. render: