diff --git a/vehicle/skoda/api.go b/vehicle/skoda/api.go index 22eb152b58..a51211cf47 100644 --- a/vehicle/skoda/api.go +++ b/vehicle/skoda/api.go @@ -77,25 +77,49 @@ 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) + // @POST("api/v1/charging/{vin}/start") + // @POST("api/v1/charging/{vin}/stop") + uri := fmt.Sprintf("%s/v1/%s/%s/%s", BaseURI, action, vin, value) - data := struct { - Typ string `json:"type"` - }{ - Typ: value, + 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 Action %s[%s] failed with status code: %d", action, value, resp.StatusCode) + } } - req, err := request.New(http.MethodPost, uri, request.MarshalJSON(data), request.JSONEncoding) + 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 { - // {"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 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() +}