From 0fca42671cd0e746ab7ca45ed76cce46cb806fd4 Mon Sep 17 00:00:00 2001 From: Michael Hess Date: Thu, 6 Jun 2024 20:17:21 +0200 Subject: [PATCH 1/2] adjust charge start/stop to mySkoda --- vehicle/skoda/api.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/vehicle/skoda/api.go b/vehicle/skoda/api.go index 22eb152b58..872cf7465a 100644 --- a/vehicle/skoda/api.go +++ b/vehicle/skoda/api.go @@ -77,22 +77,19 @@ func (v *API) Climater(vin string) (ClimaterResponse, error) { const ( ActionCharge = "charging" - ActionChargeStart = "Start" - ActionChargeStop = "Stop" + ActionChargeStart = "start" + ActionChargeStop = "stop" ) // Action executes a vehicle action func (v *API) Action(vin, action, value string) error { var res map[string]interface{} - uri := fmt.Sprintf("%s/v1/%s/operation-requests?vin=%s", BaseURI, action, vin) - data := struct { - Typ string `json:"type"` - }{ - Typ: value, - } + // @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, request.MarshalJSON(data), request.JSONEncoding) + req, err := request.New(http.MethodPost, uri, nil, request.JSONEncoding) if err == nil { // {"id":"61991908906fa40af9a5cba4","status":"InProgress","deeplink":""} err = v.DoJSON(req, &res) From 33e33877f35ad4e7f566221dfe45d59388ebb177 Mon Sep 17 00:00:00 2001 From: Michael Hess Date: Thu, 6 Jun 2024 20:42:23 +0200 Subject: [PATCH 2/2] add Ressurector; add non-202 error handling --- vehicle/skoda/api.go | 35 +++++++++++++++++++++++++++++++---- vehicle/skoda/provider.go | 11 +++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/vehicle/skoda/api.go b/vehicle/skoda/api.go index 872cf7465a..a51211cf47 100644 --- a/vehicle/skoda/api.go +++ b/vehicle/skoda/api.go @@ -83,16 +83,43 @@ const ( // Action executes a vehicle action func (v *API) Action(vin, action, value string) error { - var res map[string]interface{} - // @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 { - // {"id":"61991908906fa40af9a5cba4","status":"InProgress","deeplink":""} - err = v.DoJSON(req, &res) + var resp *http.Response + resp, err = v.Do(req) + if err != nil { + return err + } + + defer resp.Body.Close() + if resp.StatusCode != http.StatusAccepted { + err = fmt.Errorf("Vehicle Action %s[%s] failed with status code: %d", action, value, resp.StatusCode) + } + } + + 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 { + var resp *http.Response + resp, err = v.Do(req) + if err != nil { + return err + } + + defer resp.Body.Close() + if resp.StatusCode != http.StatusAccepted { + err = fmt.Errorf("Vehicle wake up failed with status code: %d", resp.StatusCode) + } } return err diff --git a/vehicle/skoda/provider.go b/vehicle/skoda/provider.go index 595c4f199a..ebe9190a84 100644 --- a/vehicle/skoda/provider.go +++ b/vehicle/skoda/provider.go @@ -14,6 +14,7 @@ type Provider struct { settingsG func() (SettingsResponse, error) climateG func() (ClimaterResponse, error) action func(action, value string) error + wakeup func() error } // NewProvider creates a vehicle api provider @@ -34,6 +35,9 @@ func NewProvider(api *API, vin string, cache time.Duration) *Provider { action: func(action, value string) error { return api.Action(vin, action, value) }, + wakeup: func() error { + return api.WakeUp(vin) + }, } return impl } @@ -149,3 +153,10 @@ func (v *Provider) ChargeEnable(enable bool) error { action := map[bool]string{true: ActionChargeStart, false: ActionChargeStop} return v.action(ActionCharge, action[enable]) } + +var _ api.Resurrector = (*Provider)(nil) + +// WakeUp implements the api.Resurrector interface +func (v *Provider) WakeUp() error { + return v.wakeup() +}