-
-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move MySkoda implementation into own package (#14349)
- Loading branch information
1 parent
85b14d3
commit 9ff704e
Showing
12 changed files
with
449 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package connect | ||
|
||
import ( | ||
"net/url" | ||
) | ||
|
||
// Skoda connect api | ||
var AuthParams = url.Values{ | ||
"response_type": {"code id_token"}, | ||
"redirect_uri": {"skodaconnect://oidc.login/"}, | ||
"client_id": {"7f045eee-7003-4379-9968-9355ed2adb06@apps_vw-dilab_com"}, | ||
"scope": {"openid profile mbb mileage"}, // phone address cars email birthdate badge dealers driversLicense | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package myskoda | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/evcc-io/evcc/util" | ||
"github.com/evcc-io/evcc/util/request" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
const BaseURI = "https://mysmob.api.connect.skoda-auto.cz/api" | ||
|
||
// API is the Skoda api client | ||
type API struct { | ||
*request.Helper | ||
} | ||
|
||
// NewAPI creates a new api client | ||
func NewAPI(log *util.Logger, ts oauth2.TokenSource) *API { | ||
v := &API{ | ||
Helper: request.NewHelper(log), | ||
} | ||
|
||
v.Client.Transport = &oauth2.Transport{ | ||
Source: ts, | ||
Base: v.Client.Transport, | ||
} | ||
|
||
return v | ||
} | ||
|
||
// Vehicles implements the /v2/garage response | ||
func (v *API) Vehicles() ([]Vehicle, error) { | ||
var res VehiclesResponse | ||
|
||
uri := fmt.Sprintf("%s/v2/garage", BaseURI) | ||
err := v.GetJSON(uri, &res) | ||
|
||
return res.Vehicles, err | ||
} | ||
|
||
func (v *API) VehicleDetails(vin string) (Vehicle, error) { | ||
var res Vehicle | ||
uri := fmt.Sprintf("%s/v2/garage/vehicles/%s", BaseURI, vin) | ||
err := v.GetJSON(uri, &res) | ||
return res, err | ||
} | ||
|
||
// Status implements the /v2/vehicle-status/<vin> response | ||
func (v *API) Status(vin string) (StatusResponse, error) { | ||
var res StatusResponse | ||
uri := fmt.Sprintf("%s/v1/vehicle-health-report/warning-lights/%s", BaseURI, vin) | ||
err := v.GetJSON(uri, &res) | ||
return res, err | ||
} | ||
|
||
// Charger implements the /v1/charging/<vin> response | ||
func (v *API) Charger(vin string) (ChargerResponse, error) { | ||
var res ChargerResponse | ||
uri := fmt.Sprintf("%s/v1/charging/%s", BaseURI, vin) | ||
err := v.GetJSON(uri, &res) | ||
return res, err | ||
} | ||
|
||
// Settings implements the /v1/charging/<vin>/settings response | ||
func (v *API) Settings(vin string) (SettingsResponse, error) { | ||
var res SettingsResponse | ||
|
||
chrgRes, err := v.Charger(vin) | ||
if err == nil { | ||
res = chrgRes.Settings | ||
} | ||
return res, err | ||
} | ||
|
||
// Climater implements the /v2/air-conditioning/<vin> response | ||
func (v *API) Climater(vin string) (ClimaterResponse, error) { | ||
var res ClimaterResponse | ||
uri := fmt.Sprintf("%s/v2/air-conditioning/%s", BaseURI, vin) | ||
err := v.GetJSON(uri, &res) | ||
return res, err | ||
} | ||
|
||
const ( | ||
ActionCharge = "charging" | ||
ActionChargeStart = "start" | ||
ActionChargeStop = "stop" | ||
) | ||
|
||
// Action executes a vehicle action | ||
func (v *API) Action(vin, action, value string) error { | ||
// @POST("api/v1/charging/{vin}/start") | ||
// @POST("api/v1/charging/{vin}/stop") | ||
uri := fmt.Sprintf("%s/v1/%s/%s/%s", BaseURI, action, vin, value) | ||
|
||
req, err := request.New(http.MethodPost, uri, nil, request.JSONEncoding) | ||
if err == nil { | ||
err = v.DoJSON(req, nil) | ||
} | ||
return err | ||
} | ||
|
||
func (v *API) WakeUp(vin string) error { | ||
// @POST("api/v1/vehicle-wakeup/{vin}") | ||
uri := fmt.Sprintf("%s/v1/vehicle-wakeup/%s", BaseURI, vin) | ||
|
||
req, err := request.New(http.MethodPost, uri, nil, request.JSONEncoding) | ||
if err == nil { | ||
err = v.DoJSON(req, nil) | ||
} | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package myskoda | ||
|
||
import "net/url" | ||
|
||
const ( | ||
Brand = "VW" | ||
Country = "CZ" | ||
|
||
// Authorization ClientID | ||
AuthClientID = "afb0473b-6d82-42b8-bfea-cead338c46ef" | ||
) | ||
|
||
// Skoda native api | ||
var AuthParams = url.Values{ | ||
"response_type": {"code id_token"}, | ||
"client_id": {"7f045eee-7003-4379-9968-9355ed2adb06@apps_vw-dilab_com"}, | ||
"redirect_uri": {"myskoda://redirect/login/"}, | ||
"scope": {"address badge birthdate cars driversLicense dealers email mileage mbb nationalIdentifier openid phone profession profile vin"}, | ||
} | ||
|
||
// TokenRefreshService parameters | ||
var TRSParams = url.Values{ | ||
"brand": {"skoda"}, | ||
} |
Oops, something went wrong.