From 47ca5e14deae4d8386bba359fa09bc8913b2ae49 Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 21 Mar 2023 22:03:01 +0100 Subject: [PATCH] chore: fix negative remaining plan duration --- core/loadpoint.go | 2 +- core/loadpoint_plan.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index d2310c4a2..2261e9992 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -731,7 +731,7 @@ func (lp *Loadpoint) setStatus(status api.ChargeStatus) { // remainingChargeEnergy returns missing energy amount in kWh if vehicle has a valid energy target func (lp *Loadpoint) remainingChargeEnergy() (float64, bool) { - return float64(lp.targetEnergy) - lp.getChargedEnergy()/1e3, + return math.Max(0, lp.targetEnergy-lp.getChargedEnergy()/1e3), (lp.vehicle == nil || lp.vehicleHasFeature(api.Offline)) && lp.targetEnergy > 0 } diff --git a/core/loadpoint_plan.go b/core/loadpoint_plan.go index ed5c90865..2a9aa7c28 100644 --- a/core/loadpoint_plan.go +++ b/core/loadpoint_plan.go @@ -37,6 +37,9 @@ func (lp *Loadpoint) planRequiredDuration(maxPower float64) time.Duration { } requiredDuration = lp.socEstimator.RemainingChargeDuration(targetSoc, maxPower) + if requiredDuration <= 0 { + return 0 + } // anticipate lower charge rates at end of charging curve var additionalDuration time.Duration