Ovms: improve retry behaviour (#1713)
This commit is contained in:
parent
8d7a7b31bb
commit
e61aabf40f
1 changed files with 6 additions and 3 deletions
|
|
@ -36,6 +36,8 @@ type Ovms struct {
|
|||
*embed
|
||||
*request.Helper
|
||||
user, password, vehicleId, server string
|
||||
cache time.Duration
|
||||
isOnline bool
|
||||
chargeG func() (interface{}, error)
|
||||
statusG func() (interface{}, error)
|
||||
}
|
||||
|
|
@ -67,6 +69,7 @@ func NewOvmsFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
password: cc.Password,
|
||||
vehicleId: cc.VehicleID,
|
||||
server: cc.Server,
|
||||
cache: cc.Cache,
|
||||
}
|
||||
|
||||
v.chargeG = provider.NewCached(v.batteryAPI, cc.Cache).InterfaceGetter()
|
||||
|
|
@ -117,8 +120,8 @@ func (v *Ovms) authFlow() error {
|
|||
err := v.loginToServer()
|
||||
if err == nil {
|
||||
resp, err = v.connectRequest()
|
||||
if err == nil && resp.NetConnected != 1 {
|
||||
return api.ErrMustRetry
|
||||
if err == nil {
|
||||
v.isOnline = resp.NetConnected == 1
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
|
@ -137,7 +140,7 @@ func (v *Ovms) batteryAPI() (interface{}, error) {
|
|||
}
|
||||
|
||||
messageAge := time.Duration(resp.MessageAgeServer) * time.Second
|
||||
if err == nil && messageAge > time.Minute {
|
||||
if err == nil && v.isOnline && messageAge > v.cache {
|
||||
err = api.ErrMustRetry
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue