Skoda Enyaq: add start/stop charger command (#1905)

This commit is contained in:
andig 2021-11-20 17:05:10 +01:00 • committed by GitHub
parent a7f563d004
commit c19f279484
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 86 additions and 67 deletions

View file

@ -58,7 +58,8 @@ func decodeJSON(resp *http.Response, res interface{}) error {
return json.NewDecoder(resp.Body).Decode(&res)
}
// DoJSON executes HTTP request and decodes JSON response. It returns a StatusError on response codes other than HTTP 2xx.
// DoJSON executes HTTP request and decodes JSON response.
// It returns a StatusError on response codes other than HTTP 2xx.
func (r *Helper) DoJSON(req *http.Request, res interface{}) error {
resp, err := r.Do(req)
if err == nil {
@ -68,12 +69,12 @@ func (r *Helper) DoJSON(req *http.Request, res interface{}) error {
return err
}
// GetJSON executes HTTP GET request and decodes JSON response. It returns a StatusError on response codes other than HTTP 2xx.
// GetJSON executes HTTP GET request and decodes JSON response.
// It returns a StatusError on response codes other than HTTP 2xx.
func (r *Helper) GetJSON(url string, res interface{}) error {
resp, err := r.Get(url)
req, err := New(http.MethodGet, url, nil, AcceptJSON)
if err == nil {
defer resp.Body.Close()
err = decodeJSON(resp, &res)
err = r.DoJSON(req, &res)
}
return err
}