chore: fix negative remaining plan duration

This commit is contained in:
andig 2023-03-21 22:03:01 +01:00
parent d5616214a4
commit 47ca5e14de
2 changed files with 4 additions and 1 deletions

View file

@ -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
}

View file

@ -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