Skip to content

Commit

Permalink
Revert "Renault: remove climater api (#15566)"
Browse files Browse the repository at this point in the history
This reverts commit b28889b.
  • Loading branch information
andig committed Aug 28, 2024
1 parent d49aa05 commit e6fb8ad
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.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

2 comments on commit e6fb8ad

@maatinh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[renault] TRACE 2024/09/11 13:39:32 {"data":{"id":"XXXXXXX","attributes":{"hvacStatus":"unavailable","lastUpdateTime":"2024-09-11T11:26:26Z"}}}

When assuming climater is always active except one out of four states names in the list are returned, please add "unavailable" to the list.

@andig
Copy link
Member Author

@andig andig commented on e6fb8ad Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is horrible. What is needed is a positiv id for the climater.

Please sign in to comment.