From 6c24407eda57298bbbf5f0e1ddf4a346d1466728 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 4 Jun 2023 10:41:36 +0200 Subject: [PATCH] Use maximum phase current as effective value (#8297) --- core/helper.go | 16 ++++++++++++++++ core/loadpoint.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/helper.go b/core/helper.go index 00d58df4c..fe6117522 100644 --- a/core/helper.go +++ b/core/helper.go @@ -5,6 +5,7 @@ import ( "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/util" "github.com/samber/lo" + "golang.org/x/exp/constraints" ) var ( @@ -46,3 +47,18 @@ func vehicleTitles(vehicles []api.Vehicle) []string { return v.Title() }) } + +// max of slice values +func max[T constraints.Ordered](s []T) T { + if len(s) == 0 { + var zero T + return zero + } + m := s[0] + for _, v := range s { + if v > m { + m = v + } + } + return m +} diff --git a/core/loadpoint.go b/core/loadpoint.go index ea39fa351..5d659a9b7 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -862,7 +862,7 @@ func (lp *Loadpoint) effectiveCurrent() float64 { // adjust actual current for vehicles like Zoe where it remains below target if lp.chargeCurrents != nil { - cur := lp.chargeCurrents[0] + cur := max(lp.chargeCurrents) return math.Min(cur+2.0, lp.chargeCurrent) }