Renault: add position and start/stop charge (#9499)
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

Co-authored-by: Elina Urbanovich <e.urbanovich@andersenlab.com>
This commit is contained in:
Elina Urbanovich 2023-08-22 22:36:24 +03:00 • committed by GitHub
parent 748d2f5d3d
commit 0c0e1f57b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 0 deletions

View file

@ -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
@ -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))
}

View file

@ -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"`
}

View file

@ -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
@ -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
}
@ -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
}