Add support for Porsche PHEVs (#1236)

This commit is contained in:
Andreas Linde 2021-07-22 21:36:27 +02:00 • committed by GitHub
parent 3e33a72176
commit f4976d64a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 6 deletions

View file

@ -229,11 +229,8 @@ func (v *Identity) FindVehicle(accessTokens AccessTokens, vin string) (Vehicle,
if foundVehicle.VIN != "" {
v.log.DEBUG.Printf("found vehicle: %v", foundVehicle.VIN)
// check if the found vehicle is a Taycan, because that one supports the emobility API
if accessTokens.EmobilityToken.AccessToken != "" {
if strings.Contains(foundVehicle.ModelDescription, "Taycan") {
foundEmobilityVehicle = true
}
foundEmobilityVehicle = true
}
} else {
err = errors.New("vin not found")

View file

@ -12,6 +12,24 @@ import (
"golang.org/x/oauth2"
)
type CapabilitiesResponse struct {
DisplayParkingBrake bool
NeedsSPIN bool
HasRDK bool
EngineType string
CarModel string
OnlineRemoteUpdateStatus struct {
EditableByUser bool
Active bool
}
HeatingCapabilities struct {
FrontSeatHeatingAvailable bool
RearSeatHeatingAvailable bool
}
SteeringWheelPosition string
HasHonkAndFlash bool
}
type EmobilityResponse struct {
BatteryChargeStatus struct {
ChargeRate struct {
@ -54,6 +72,7 @@ type EMobilityProvider struct {
*request.Helper
token oauth2.Token
identity *Identity
carModel string
statusG func() (interface{}, error)
}
@ -84,6 +103,7 @@ func (v *EMobilityProvider) request(uri string) (*http.Request, error) {
req, err := request.New(http.MethodGet, uri, nil, map[string]string{
"Authorization": fmt.Sprintf("Bearer %s", v.token.AccessToken),
"apikey": EmobilityClientID,
})
return req, err
@ -91,13 +111,29 @@ func (v *EMobilityProvider) request(uri string) (*http.Request, error) {
// Status implements the vehicle status response
func (v *EMobilityProvider) status(vin string) (interface{}, error) {
uri := fmt.Sprintf("https://api.porsche.com/service-vehicle/de/de_DE/e-mobility/J1/%s?timezone=Europe/Berlin", vin)
if v.carModel == "" {
uri := fmt.Sprintf("https://api.porsche.com/service-vehicle/vcs/capabilities/%s", vin)
req, err := v.request(uri)
if err != nil {
return 0, err
}
req.Header.Set("x-vrs-url-country", "de")
req.Header.Set("x-vrs-url-language", "de_DE")
var cr CapabilitiesResponse
err = v.DoJSON(req, &cr)
if err != nil {
return 0, err
}
v.carModel = cr.CarModel
}
uri := fmt.Sprintf("https://api.porsche.com/service-vehicle/de/de_DE/e-mobility/%s/%s?timezone=Europe/Berlin", v.carModel, vin)
req, err := v.request(uri)
if err != nil {
return 0, err
}
req.Header.Set("apikey", EmobilityClientID)
var pr EmobilityResponse
err = v.DoJSON(req, &pr)