Allow vehicles to request soc update (#981)
This commit is contained in:
parent
62052e0159
commit
cb93b9b2f1
3 changed files with 19 additions and 11 deletions
|
|
@ -5,6 +5,9 @@ import "errors"
|
|||
// ErrNotAvailable indicates that a feature is not available
|
||||
var ErrNotAvailable = errors.New("not available")
|
||||
|
||||
// ErrMustRetry indicates that a rate-limited operation should be retried
|
||||
var ErrMustRetry = errors.New("must retry")
|
||||
|
||||
// ErrTimeout is the error returned when a timeout happened.
|
||||
// Modeled after context.DeadlineError
|
||||
var ErrTimeout error = errTimeoutError{}
|
||||
|
|
|
|||
|
|
@ -868,12 +868,7 @@ func (lp *LoadPoint) socPollAllowed() bool {
|
|||
lp.log.DEBUG.Printf("next soc poll remaining time: %v", remaining.Truncate(time.Second))
|
||||
}
|
||||
|
||||
res := lp.charging() || honourUpdateInterval && (remaining <= 0) || lp.connected() && lp.socUpdated.IsZero()
|
||||
if res {
|
||||
lp.socUpdated = lp.clock.Now()
|
||||
}
|
||||
|
||||
return res
|
||||
return lp.charging() || honourUpdateInterval && (remaining <= 0) || lp.connected() && lp.socUpdated.IsZero()
|
||||
}
|
||||
|
||||
// publish state of charge, remaining charge duration and range
|
||||
|
|
@ -883,6 +878,8 @@ func (lp *LoadPoint) publishSoCAndRange() {
|
|||
}
|
||||
|
||||
if lp.socPollAllowed() {
|
||||
lp.socUpdated = lp.clock.Now()
|
||||
|
||||
f, err := lp.socEstimator.SoC(lp.chargedEnergy)
|
||||
if err == nil {
|
||||
lp.socCharge = math.Trunc(f)
|
||||
|
|
@ -898,10 +895,12 @@ func (lp *LoadPoint) publishSoCAndRange() {
|
|||
chargeRemainingEnergy := 1e3 * lp.socEstimator.RemainingChargeEnergy(lp.SoC.Target)
|
||||
lp.publish("chargeRemainingEnergy", chargeRemainingEnergy)
|
||||
} else {
|
||||
// we need a value- so retry on error
|
||||
lp.socUpdated = lp.clock.Now()
|
||||
|
||||
lp.log.ERROR.Printf("vehicle: %v", err)
|
||||
if errors.Is(err, api.ErrMustRetry) {
|
||||
lp.socUpdated = time.Time{}
|
||||
lp.log.DEBUG.Printf("vehicle: waiting for update")
|
||||
} else {
|
||||
lp.log.ERROR.Printf("vehicle: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// range
|
||||
|
|
|
|||
|
|
@ -699,7 +699,13 @@ func TestSoCPoll(t *testing.T) {
|
|||
lp.SoC.Poll.Mode = tc.mode
|
||||
lp.status = tc.status
|
||||
|
||||
if res := lp.socPollAllowed(); tc.res != res {
|
||||
res := lp.socPollAllowed()
|
||||
if res {
|
||||
// mimic update outside of socPollAllowed
|
||||
lp.socUpdated = clock.Now()
|
||||
}
|
||||
|
||||
if tc.res != res {
|
||||
t.Errorf("expected %v, got %v", tc.res, res)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue