From bf169061c07c98e0f7cccb3e8df9c5afdce67445 Mon Sep 17 00:00:00 2001 From: premultiply Date: Mon, 28 Feb 2022 13:10:17 +0100 Subject: [PATCH] Fix NaN if vehicle.capacity is not set (#2732) Fixes #2730 --- core/soc/estimator.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/soc/estimator.go b/core/soc/estimator.go index 0f09686d6..b79e4ac4f 100644 --- a/core/soc/estimator.go +++ b/core/soc/estimator.go @@ -57,7 +57,7 @@ func (s *Estimator) Reset() { func (s *Estimator) AssumedChargeDuration(targetSoC int, chargePower float64) time.Duration { percentRemaining := float64(targetSoC) - s.vehicleSoc - if percentRemaining <= 0 { + if percentRemaining <= 0 || s.virtualCapacity <= 0 { return 0 } @@ -95,7 +95,7 @@ func (s *Estimator) RemainingChargeDuration(chargePower float64, targetSoC int) // RemainingChargeEnergy returns the remaining charge energy in kWh func (s *Estimator) RemainingChargeEnergy(targetSoC int) float64 { percentRemaining := float64(targetSoC) - s.vehicleSoc - if percentRemaining <= 0 { + if percentRemaining <= 0 || s.virtualCapacity <= 0 { return 0 } @@ -151,7 +151,7 @@ func (s *Estimator) SoC(chargedEnergy float64) (float64, error) { s.vehicleSoc = f } - if s.estimate { + if s.estimate && s.virtualCapacity > 0 { socDelta := s.vehicleSoc - s.prevSoc energyDelta := math.Max(chargedEnergy, 0) - s.prevChargedEnergy