From 9d04e561a9f31a60fcccfeb3f7951349509a8f90 Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 28 Sep 2020 17:08:46 +0200 Subject: [PATCH] Gracefully handle when remaining time estimate is not available --- api/error.go | 6 ++++++ core/wrapper/socestimator.go | 5 ++++- vehicle/renault.go | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 api/error.go diff --git a/api/error.go b/api/error.go new file mode 100644 index 000000000..17180a634 --- /dev/null +++ b/api/error.go @@ -0,0 +1,6 @@ +package api + +import "errors" + +// ErrNotAvailable indicates that a feature is not available +var ErrNotAvailable = errors.New("not available") diff --git a/core/wrapper/socestimator.go b/core/wrapper/socestimator.go index d06d82d80..64caf1774 100644 --- a/core/wrapper/socestimator.go +++ b/core/wrapper/socestimator.go @@ -1,6 +1,7 @@ package wrapper import ( + "errors" "math" "time" @@ -63,7 +64,9 @@ func (s *SocEstimator) RemainingChargeDuration(chargePower float64, targetSoC in return time.Duration(float64(timeRemaining) * percentRemaining / (100 - s.socCharge)) } - s.log.WARN.Printf("updating remaining time failed: %v", err) + if !errors.Is(err, api.ErrNotAvailable) { + s.log.WARN.Printf("updating remaining time failed: %v", err) + } } // estimate remaining time diff --git a/vehicle/renault.go b/vehicle/renault.go index 7a9381e4a..0e956df61 100644 --- a/vehicle/renault.go +++ b/vehicle/renault.go @@ -333,7 +333,7 @@ func (v *Renault) finishTime() (time.Time, error) { } if kr.Data.Attributes.RemainingTime == nil { - return time.Time{}, errors.New("estimate not available") + return time.Time{}, api.ErrNotAvailable } return timestamp.Add(time.Duration(*kr.Data.Attributes.RemainingTime) * time.Minute), err