Cardata: require vin (BC)
This commit is contained in:
parent
22263b5c2e
commit
97567762ca
2 changed files with 6 additions and 15 deletions
|
|
@ -41,6 +41,7 @@ requirements:
|
|||
params:
|
||||
- preset: vehicle-common
|
||||
- name: vin
|
||||
required: true
|
||||
example: WBMW...
|
||||
- name: clientid
|
||||
required: true
|
||||
|
|
|
|||
|
|
@ -4,13 +4,11 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/plugin/auth"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/vehicle/bmw/cardata"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
|
@ -39,6 +37,10 @@ func NewCardataFromConfig(ctx context.Context, other map[string]interface{}) (ap
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if cc.VIN == "" {
|
||||
return nil, errors.New("missing vin")
|
||||
}
|
||||
|
||||
if cc.ClientID == "" {
|
||||
return nil, api.ErrMissingCredentials
|
||||
}
|
||||
|
|
@ -75,19 +77,7 @@ func NewCardataFromConfig(ctx context.Context, other map[string]interface{}) (ap
|
|||
|
||||
api := cardata.NewAPI(log, ts)
|
||||
|
||||
is429 := func(err error) bool {
|
||||
se := new(request.StatusError)
|
||||
return errors.As(err, &se) && se.StatusCode() == http.StatusTooManyRequests
|
||||
}
|
||||
|
||||
vehicle, err := ensureVehicle(
|
||||
cc.VIN, api.Vehicles,
|
||||
)
|
||||
if err != nil && (cc.VIN == "" || !is429(err)) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v.Provider = cardata.NewProvider(ctx, log, api, ts, cc.ClientID, vehicle)
|
||||
v.Provider = cardata.NewProvider(ctx, log, api, ts, cc.ClientID, cc.VIN)
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue