Gracefully handle when remaining time estimate is not available

This commit is contained in:
andig 2020-09-28 17:08:46 +02:00
parent d73c374577
commit 9d04e561a9
3 changed files with 11 additions and 2 deletions

6
api/error.go Normal file
View file

@ -0,0 +1,6 @@
package api
import "errors"
// ErrNotAvailable indicates that a feature is not available
var ErrNotAvailable = errors.New("not available")

View file

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

View file

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