From 81b3d44539ae336cc9c0aba41462d1ebcab732e7 Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 17 Jan 2025 14:40:46 +0100 Subject: [PATCH] myPV: fix power calculation (#18257) --- charger/mypv.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/charger/mypv.go b/charger/mypv.go index fe53061d68..e20d7e40ba 100644 --- a/charger/mypv.go +++ b/charger/mypv.go @@ -24,6 +24,7 @@ import ( "time" "github.com/evcc-io/evcc/api" + "github.com/evcc-io/evcc/core/loadpoint" "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/modbus" "github.com/evcc-io/evcc/util/sponsor" @@ -33,6 +34,7 @@ import ( type MyPv struct { log *util.Logger conn *modbus.Connection + lp loadpoint.API power uint32 statusC uint16 enabled bool @@ -191,7 +193,13 @@ var _ api.ChargerEx = (*MyPv)(nil) // MaxCurrentMillis implements the api.ChargerEx interface func (wb *MyPv) MaxCurrentMillis(current float64) error { - power := uint16(230 * current) + phases := 1 + if wb.lp != nil { + if p := wb.lp.GetPhases(); p != 0 { + phases = p + } + } + power := uint16(voltage * current * float64(phases)) err := wb.setPower(power) if err == nil { @@ -237,9 +245,9 @@ func (wb *MyPv) GetLimitSoc() (int64, error) { return int64(binary.BigEndian.Uint16(b)) / 10, nil } -var _ api.PhaseDescriber = (*MyPv)(nil) +var _ loadpoint.Controller = (*MyPv)(nil) -// Phases implements the api.PhasesDescriber interface -func (wb *MyPv) Phases() int { - return 1 +// LoadpointControl implements loadpoint.Controller +func (wb *MyPv) LoadpointControl(lp loadpoint.API) { + wb.lp = lp }