Skip to content

Commit

Permalink
Renault: add position and start/stop charge (evcc-io#9499)
Browse files Browse the repository at this point in the history
Co-authored-by: Elina Urbanovich <e.urbanovich@andersenlab.com>
  • Loading branch information
ElinaUrbanovich and Elina Urbanovich authored Aug 22, 2023
1 parent 748d2f5 commit 0c0e1f5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
25 changes: 25 additions & 0 deletions vehicle/renault/kamereon/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
"github.com/evcc-io/evcc/vehicle/renault/keys"
)

const (
ActionStart = "start"
ActionStop = "stop"
)

type API struct {
*request.Helper
keys keys.ConfigServer
Expand Down Expand Up @@ -118,3 +123,23 @@ func (v *API) WakeUp(accountID string, vin string) (Response, error) {

return v.request(uri, request.MarshalJSON(data))
}

func (v *API) Position(accountID string, vin string) (Response, error) {
uri := fmt.Sprintf("%s/commerce/v1/accounts/%s/kamereon/kca/car-adapter/v1/cars/%s/location", v.keys.Target, accountID, vin)
return v.request(uri, nil)
}

func (v *API) Action(accountID, action string, vin string) (Response, error) {
uri := fmt.Sprintf("%s/commerce/v1/accounts/%s/kamereon/kca/car-adapter/v1/cars/%s/actions/charging-start", v.keys.Target, accountID, vin)

data := map[string]interface{}{
"data": map[string]interface{}{
"type": "ChargingStart",
"attributes": map[string]interface{}{
"action": action,
},
},
}

return v.request(uri, request.MarshalJSON(data))
}
3 changes: 3 additions & 0 deletions vehicle/renault/kamereon/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ type attributes struct {
HvacStatus string `json:"hvacStatus"`
// cockpit
TotalMileage float64 `json:"totalMileage"`
// position
Latitude float64 `json:"gpsLatitude"`
Longitude float64 `json:"gpsLongitude"`
}
34 changes: 34 additions & 0 deletions vehicle/renault/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Provider struct {
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)
}

// NewProvider creates a vehicle api provider
Expand All @@ -35,6 +37,12 @@ func NewProvider(api *kamereon.API, accountID, vin string, cache time.Duration)
wakeup: func() (kamereon.Response, error) {
return api.WakeUp(accountID, vin)
},
position: func() (kamereon.Response, error) {
return api.Position(accountID, vin)
},
action: func(action string) (kamereon.Response, error) {
return api.Action(accountID, action, vin)
},
}
return impl
}
Expand Down Expand Up @@ -147,3 +155,29 @@ func (v *Provider) WakeUp() error {
_, err := v.wakeup()
return err
}

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

// Position implements the api.VehiclePosition interface
func (v *Provider) Position() (float64, float64, error) {
res, err := v.position()
if err == nil {
return res.Data.Attributes.Latitude, res.Data.Attributes.Longitude, nil
}

return 0, 0, err
}

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

// StartCharge implements the api.VehicleChargeController interface
func (v *Provider) StartCharge() error {
_, err := v.action(kamereon.ActionStart)
return err
}

// StopCharge implements the api.VehicleChargeController interface
func (v *Provider) StopCharge() error {
_, err := v.action(kamereon.ActionStart)
return err
}

0 comments on commit 0c0e1f5

Please sign in to comment.