Audi e-tron: add timeout to query
This commit is contained in:
parent
2de39cadb2
commit
9abaa2ff3b
2 changed files with 8 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package vehicle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
|
|
@ -64,7 +65,11 @@ func NewEtronFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
// use the etron API for list of vehicles
|
||||
api := etron.NewAPI(log, ats)
|
||||
|
||||
cc.VIN, err = ensureVehicle(cc.VIN, api.Vehicles)
|
||||
cc.VIN, err = ensureVehicle(cc.VIN, func() ([]string, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), cc.Timeout)
|
||||
defer cancel()
|
||||
return api.Vehicles(ctx)
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
api := id.NewAPI(log, its)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func NewAPI(log *util.Logger, ts oauth2.TokenSource) *API {
|
|||
}
|
||||
|
||||
// Vehicles implements the /vehicles response
|
||||
func (v *API) Vehicles() ([]string, error) {
|
||||
func (v *API) Vehicles(ctx context.Context) ([]string, error) {
|
||||
type vehicle struct {
|
||||
VIN, Type, Nickname string
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ func (v *API) Vehicles() ([]string, error) {
|
|||
}
|
||||
|
||||
var vins []string
|
||||
err := v.client.Query(context.Background(), &res, nil)
|
||||
err := v.client.Query(ctx, &res, nil)
|
||||
if err == nil {
|
||||
vins = funk.Map(res.UserVehicles, func(v vehicle) string {
|
||||
return v.VIN
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue