Renault: add position and start/stop charge (#9499)
Some checks failed
Some checks failed
Co-authored-by: Elina Urbanovich <e.urbanovich@andersenlab.com>
This commit is contained in:
parent
748d2f5d3d
commit
0c0e1f57b4
3 changed files with 62 additions and 0 deletions
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue