Porsche: simplify login (#2960)

This commit is contained in:
andig 2022-03-24 17:35:46 +01:00 • committed by GitHub
parent 7aa179419b
commit af46b731fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -73,32 +73,11 @@ func NewPorscheFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, errors.New("vehicle is not paired with the My Porsche account")
}
// check if vehicle provides status:
// some PHEVs do not provide any data
statusAvailable := false
if _, err := mobile.Status(cc.VIN); err == nil {
statusAvailable = true
}
if _, err := api.Status(cc.VIN); err == nil {
statusAvailable = true
}
if !statusAvailable {
return nil, errors.New("vehicle is not capable of providing data")
}
// get eMobility capabilities
// Note: As of 27.10.21 the capabilities API needs to be called AFTER a
// call to status() as it otherwise returns an HTTP 502 error.
// The reason is unknown, even when tested with 100% identical Headers.
// It seems to be a new backend related issue.
var emobility *porsche.EmobilityAPI
var capabilities porsche.CapabilitiesResponse
if _, err := api.Status(cc.VIN); err == nil {
emobility = porsche.NewEmobilityAPI(log, identity.EmobilitySource)
capabilities, _ = emobility.Capabilities(cc.VIN)
emobility := porsche.NewEmobilityAPI(log, identity.EmobilitySource)
capabilities, err := emobility.Capabilities(cc.VIN)
if err != nil {
return nil, err
}
provider := porsche.NewProvider(log, api, emobility, mobile, cc.VIN, capabilities.CarModel, cc.Cache)