Skip to content

Commit

Permalink
Merge branch 'feat/mySkoda' into nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimmiMeloni committed Jun 6, 2024
2 parents 2eca804 + 33e3387 commit 6296351
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
46 changes: 35 additions & 11 deletions vehicle/skoda/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions vehicle/skoda/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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()
}

0 comments on commit 6296351

Please sign in to comment.