Easee: prevent internal current updates on failed API calls (#7825)

* prevent internal current updates on failed API calls

* incorporate review feedback on error handling

* wip

---------

Co-authored-by: andig <cpuidle@gmx.de>
This commit is contained in:
Michael Heß 2023-05-16 16:36:43 +02:00 • committed by GitHub
parent c46c9372ac
commit 4e66c01803
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -415,8 +415,12 @@ func (c *Easee) MaxCurrent(current int64) error {
uri := fmt.Sprintf("%s/chargers/%s/settings", easee.API, c.charger)
resp, err := c.Post(uri, request.JSONContent, request.MarshalJSON(data))
if err == nil {
c.current = cur
resp.Body.Close()
if resp.StatusCode == 202 && resp.ContentLength <= 2 {
// no tick id, Easee effectively ignored this update
return api.ErrMustRetry
}
c.current = cur
}
return err