parent
8769ae489d
commit
a68f23e483
3 changed files with 16 additions and 6 deletions
|
|
@ -58,9 +58,7 @@ func NewSmartHelloFromConfig(other map[string]any) (api.Vehicle, error) {
|
|||
return v, err
|
||||
}
|
||||
|
||||
if vehicle.ProprietaryPlatform != 0 {
|
||||
return v, fmt.Errorf("unsupported vehicle platform: %s", vehicle.SeriesCodeVs)
|
||||
}
|
||||
api.SetSeries(vehicle.SeriesCodeVs)
|
||||
|
||||
v.Provider = hello.NewProvider(log, api, vehicle.VIN, cc.Cache)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ import (
|
|||
type API struct {
|
||||
*request.Helper
|
||||
identity *Identity
|
||||
baseURI string
|
||||
}
|
||||
|
||||
func NewAPI(log *util.Logger, identity *Identity) *API {
|
||||
v := &API{
|
||||
Helper: request.NewHelper(log),
|
||||
identity: identity,
|
||||
baseURI: ApiURI,
|
||||
}
|
||||
|
||||
v.Client.Transport = &transport.Decorator{
|
||||
|
|
@ -54,6 +56,14 @@ func NewAPI(log *util.Logger, identity *Identity) *API {
|
|||
return v
|
||||
}
|
||||
|
||||
// SetSeries selects the API host for the vehicle's platform.
|
||||
// Smart #5 (series HY) is served by the V2 host; #1/#3 (HX/HC) use V1.
|
||||
func (v *API) SetSeries(series string) {
|
||||
if strings.HasPrefix(series, "HY") {
|
||||
v.baseURI = ApiURIV2
|
||||
}
|
||||
}
|
||||
|
||||
func (v *API) request(method, path string, params url.Values, body io.Reader) (*http.Request, error) {
|
||||
if body != nil {
|
||||
b, err := io.ReadAll(body)
|
||||
|
|
@ -74,7 +84,7 @@ func (v *API) request(method, path string, params url.Values, body io.Reader) (*
|
|||
body.(*bytes.Reader).Seek(0, io.SeekStart)
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf("%s/%s?%s", ApiURI, strings.TrimPrefix(path, "/"), params.Encode())
|
||||
uri := fmt.Sprintf("%s/%s?%s", v.baseURI, strings.TrimPrefix(path, "/"), params.Encode())
|
||||
req, err := request.New(method, uri, body, map[string]string{
|
||||
"x-api-signature-nonce": nonce,
|
||||
"x-signature": sign,
|
||||
|
|
@ -104,6 +114,7 @@ func (v *API) Vehicles() ([]Vehicle, error) {
|
|||
"userId": {userID},
|
||||
}
|
||||
|
||||
// vehicle list is fetched on V1: SetSeries runs only after this call
|
||||
path := "/device-platform/user/vehicle/secure"
|
||||
req, err := v.request(http.MethodGet, path, params, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package hello
|
||||
|
||||
const (
|
||||
ApiURI = "https://api.ecloudeu.com"
|
||||
ApiKey = "3_L94eyQ-wvJhWm7Afp1oBhfTGXZArUfSHHW9p9Pncg513hZELXsxCfMWHrF8f5P5a"
|
||||
ApiURI = "https://api.ecloudeu.com" // Smart #1/#3 (series HX/HC)
|
||||
ApiURIV2 = "https://apiv2.ecloudeu.com" // Smart #5 (series HY)
|
||||
ApiKey = "3_L94eyQ-wvJhWm7Afp1oBhfTGXZArUfSHHW9p9Pncg513hZELXsxCfMWHrF8f5P5a"
|
||||
|
||||
appID = "SmartAPPEU"
|
||||
operatorCode = "SMART"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue