Skip to content

Commit

Permalink
Merge pull request evcc-io#15757 from evcc-io/feat/renault-climater
Browse files Browse the repository at this point in the history
Renault: accept climater HTTP 404 errors
  • Loading branch information
andig authored Aug 28, 2024
2 parents d49aa05 + dbfaf01 commit f53d4de
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions vehicle/renault/provider.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package renault

import (
"net/http"
"slices"
"strings"
"time"

"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/provider"
"github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/vehicle/renault/kamereon"
)

// Provider is an api.Vehicle implementation for PSA cars
type Provider struct {
batteryG func() (kamereon.Response, error)
cockpitG func() (kamereon.Response, error)
hvacG func() (kamereon.Response, error)
wakeup func() (kamereon.Response, error)
position func() (kamereon.Response, error)
action func(action string) (kamereon.Response, error)
Expand All @@ -26,6 +31,9 @@ func NewProvider(api *kamereon.API, accountID, vin string, alternativeWakeup boo
cockpitG: provider.Cached(func() (kamereon.Response, error) {
return api.Cockpit(accountID, vin)
}, cache),
hvacG: provider.Cached(func() (kamereon.Response, error) {
return api.Hvac(accountID, vin)
}, cache),
wakeup: func() (kamereon.Response, error) {
if alternativeWakeup {
return api.Action(accountID, kamereon.ActionStart, vin)
Expand Down Expand Up @@ -125,6 +133,30 @@ func (v *Provider) FinishTime() (time.Time, error) {
return time.Time{}, err
}

var _ api.VehicleClimater = (*Provider)(nil)

// Climater implements the api.VehicleClimater interface
func (v *Provider) Climater() (bool, error) {
res, err := v.hvacG()

// Zoe Ph2, Megane e-tech
if err, ok := err.(request.StatusError); ok && err.HasStatus(http.StatusForbidden, http.StatusNotFound, http.StatusBadGateway) {
return false, api.ErrNotAvailable
}

if err == nil {
state := strings.ToLower(res.Data.Attributes.HvacStatus)
if state == "" {
return false, api.ErrNotAvailable
}

active := !slices.Contains([]string{"off", "false", "invalid", "error"}, state)
return active, nil
}

return false, err
}

var _ api.Resurrector = (*Provider)(nil)

// WakeUp implements the api.Resurrector interface
Expand Down

0 comments on commit f53d4de

Please sign in to comment.