Unify charge start/stop interfaces (#3002)
This commit is contained in:
parent
ed980c5656
commit
58d4dd5cf8
12 changed files with 47 additions and 187 deletions
|
|
@ -173,13 +173,9 @@ type VehiclePosition interface {
|
|||
Position() (float64, float64, error)
|
||||
}
|
||||
|
||||
// VehicleStartCharge starts the charging session on the vehicle side
|
||||
type VehicleStartCharge interface {
|
||||
// VehicleChargeController allows to start/stop the charging session on the vehicle side
|
||||
type VehicleChargeController interface {
|
||||
StartCharge() error
|
||||
}
|
||||
|
||||
// VehicleStopCharge stops the charging session on the vehicle side
|
||||
type VehicleStopCharge interface {
|
||||
StopCharge() error
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ func main() {
|
|||
|
||||
switch action {
|
||||
case "wakeup":
|
||||
vv, ok := v.(api.VehicleStartCharge)
|
||||
vv, ok := v.(api.VehicleChargeController)
|
||||
if !ok {
|
||||
log.Fatal("not supported:", action)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func runVehicle(cmd *cobra.Command, args []string) {
|
|||
if cmd.PersistentFlags().Lookup(flagStart).Changed {
|
||||
flagUsed = true
|
||||
|
||||
if vv, ok := v.(api.VehicleStartCharge); ok {
|
||||
if vv, ok := v.(api.VehicleChargeController); ok {
|
||||
if err := vv.StartCharge(); err != nil {
|
||||
log.ERROR.Println("start charge:", err)
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ func runVehicle(cmd *cobra.Command, args []string) {
|
|||
if cmd.PersistentFlags().Lookup(flagStop).Changed {
|
||||
flagUsed = true
|
||||
|
||||
if vv, ok := v.(api.VehicleStopCharge); ok {
|
||||
if vv, ok := v.(api.VehicleChargeController); ok {
|
||||
if err := vv.StopCharge(); err != nil {
|
||||
log.ERROR.Println("stop charge:", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -611,7 +611,7 @@ func (lp *LoadPoint) setLimit(chargeCurrent float64, force bool) error {
|
|||
|
||||
// remote stop
|
||||
// TODO https://github.com/evcc-io/evcc/discussions/1929
|
||||
// if car, ok := lp.vehicle.(api.VehicleStopCharge); !enabled && ok {
|
||||
// if car, ok := lp.vehicle.(api.VehicleChargeController); !enabled && ok {
|
||||
// // log but don't propagate
|
||||
// if err := car.StopCharge(); err != nil {
|
||||
// lp.log.ERROR.Printf("vehicle remote charge stop: %v", err)
|
||||
|
|
@ -639,7 +639,7 @@ func (lp *LoadPoint) setLimit(chargeCurrent float64, force bool) error {
|
|||
|
||||
// remote start
|
||||
// TODO https://github.com/evcc-io/evcc/discussions/1929
|
||||
// if car, ok := lp.vehicle.(api.VehicleStartCharge); enabled && ok {
|
||||
// if car, ok := lp.vehicle.(api.VehicleChargeController); enabled && ok {
|
||||
// // log but don't propagate
|
||||
// if err := car.StartCharge(); err != nil {
|
||||
// lp.log.ERROR.Printf("vehicle remote charge start: %v", err)
|
||||
|
|
|
|||
|
|
@ -123,16 +123,14 @@ func (v *Provider) Climater() (active bool, outsideTemp float64, targetTemp floa
|
|||
return active, outsideTemp, targetTemp, err
|
||||
}
|
||||
|
||||
var _ api.VehicleStartCharge = (*Provider)(nil)
|
||||
var _ api.VehicleChargeController = (*Provider)(nil)
|
||||
|
||||
// StartCharge implements the api.VehicleStartCharge interface
|
||||
// StartCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StartCharge() error {
|
||||
return v.action(ActionCharge, ActionChargeStart)
|
||||
}
|
||||
|
||||
var _ api.VehicleStopCharge = (*Provider)(nil)
|
||||
|
||||
// StopCharge implements the api.VehicleStopCharge interface
|
||||
// StopCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StopCharge() error {
|
||||
return v.action(ActionCharge, ActionChargeStop)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,16 +116,14 @@ func (v *Provider) Position() (float64, float64, error) {
|
|||
return 0, 0, err
|
||||
}
|
||||
|
||||
var _ api.VehicleStartCharge = (*Provider)(nil)
|
||||
var _ api.VehicleChargeController = (*Provider)(nil)
|
||||
|
||||
// StartCharge implements the api.VehicleStartCharge interface
|
||||
// StartCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StartCharge() error {
|
||||
return v.actionS(true)
|
||||
}
|
||||
|
||||
var _ api.VehicleStopCharge = (*Provider)(nil)
|
||||
|
||||
// StopCharge implements the api.VehicleStopCharge interface
|
||||
// StopCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StopCharge() error {
|
||||
return v.actionS(false)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,16 +141,14 @@ func (v *Provider) FinishTime() (time.Time, error) {
|
|||
return time.Time{}, err
|
||||
}
|
||||
|
||||
var _ api.VehicleStartCharge = (*Provider)(nil)
|
||||
var _ api.VehicleChargeController = (*Provider)(nil)
|
||||
|
||||
// StartCharge implements the api.VehicleStartCharge interface
|
||||
// StartCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StartCharge() error {
|
||||
return v.action(ActionChargeStart)
|
||||
}
|
||||
|
||||
var _ api.VehicleStopCharge = (*Provider)(nil)
|
||||
|
||||
// StopCharge implements the api.VehicleStopCharge interface
|
||||
// StopCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StopCharge() error {
|
||||
return v.action(ActionChargeStop)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,16 +113,14 @@ func (v *Provider) Range() (rng int64, err error) {
|
|||
// return active, outsideTemp, targetTemp, err
|
||||
// }
|
||||
|
||||
var _ api.VehicleStartCharge = (*Provider)(nil)
|
||||
var _ api.VehicleChargeController = (*Provider)(nil)
|
||||
|
||||
// StartCharge implements the api.VehicleStartCharge interface
|
||||
// StartCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StartCharge() error {
|
||||
return v.action(ActionCharge, ActionChargeStart)
|
||||
}
|
||||
|
||||
var _ api.VehicleStopCharge = (*Provider)(nil)
|
||||
|
||||
// StopCharge implements the api.VehicleStopCharge interface
|
||||
// StopCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StopCharge() error {
|
||||
return v.action(ActionCharge, ActionChargeStop)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,9 +211,9 @@ func (v *Tesla) Position() (float64, float64, error) {
|
|||
return 0, 0, err
|
||||
}
|
||||
|
||||
var _ api.VehicleStartCharge = (*Tesla)(nil)
|
||||
var _ api.VehicleChargeController = (*Tesla)(nil)
|
||||
|
||||
// StartCharge implements the api.VehicleStartCharge interface
|
||||
// StartCharge implements the api.VehicleChargeController interface
|
||||
func (v *Tesla) StartCharge() error {
|
||||
err := v.vehicle.StartCharging()
|
||||
|
||||
|
|
@ -240,9 +240,7 @@ func (v *Tesla) StartCharge() error {
|
|||
return err
|
||||
}
|
||||
|
||||
var _ api.VehicleStopCharge = (*Tesla)(nil)
|
||||
|
||||
// StopCharge implements the api.VehicleStopCharge interface
|
||||
// StopCharge implements the api.VehicleChargeController interface
|
||||
func (v *Tesla) StopCharge() error {
|
||||
err := v.vehicle.StopCharging()
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func init() {
|
|||
registry.Add("tronity", NewTronityFromConfig)
|
||||
}
|
||||
|
||||
//go:generate go run ../cmd/tools/decorate.go -f decorateTronity -b *Tronity -r api.Vehicle -t "api.ChargeState,Status,func() (api.ChargeStatus, error)" -t "api.VehicleOdometer,Odometer,func() (float64, error)" -t "api.VehicleStartCharge,StartCharge,func() error" -t "api.VehicleStopCharge,StopCharge,func() error"
|
||||
// go:generate go run ../cmd/tools/decorate.go -f decorateTronity -b *Tronity -r api.Vehicle -t "api.ChargeState,Status,func() (api.ChargeStatus, error)" -t "api.VehicleOdometer,Odometer,func() (float64, error)" -t "api.VehicleChargeController,StartCharge,func() error" -t "api.VehicleChargeController,StopCharge,func() error"
|
||||
|
||||
// NewTronityFromConfig creates a new vehicle
|
||||
func NewTronityFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
||||
|
|
@ -263,13 +263,13 @@ func (v *Tronity) post(uri string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// startCharge implements the api.VehicleStartCharge interface
|
||||
// startCharge implements the api.VehicleChargeController interface
|
||||
func (v *Tronity) startCharge() error {
|
||||
uri := fmt.Sprintf("%s/v1/vehicles/%s/charge_start", tronity.URI, v.vid)
|
||||
return v.post(uri)
|
||||
}
|
||||
|
||||
// stopCharge implements the api.VehicleStopCharge interface
|
||||
// stopCharge implements the api.VehicleChargeController interface
|
||||
func (v *Tronity) stopCharge() error {
|
||||
uri := fmt.Sprintf("%s/v1/vehicles/%s/charge_stop", tronity.URI, v.vid)
|
||||
return v.post(uri)
|
||||
|
|
|
|||
|
|
@ -48,138 +48,26 @@ func decorateTronity(base *Tronity, chargeState func() (api.ChargeStatus, error)
|
|||
},
|
||||
}
|
||||
|
||||
case chargeState == nil && vehicleOdometer == nil && vehicleStartCharge != nil && vehicleStopCharge == nil:
|
||||
case chargeState == nil && vehicleOdometer == nil && vehicleStartCharge != nil && vehicleStopCharge != nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.VehicleStartCharge
|
||||
api.VehicleChargeController
|
||||
}{
|
||||
Tronity: base,
|
||||
VehicleStartCharge: &decorateTronityVehicleStartChargeImpl{
|
||||
VehicleChargeController: &decorateTronityVehicleChargeControllerImpl{
|
||||
vehicleStartCharge: vehicleStartCharge,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeState != nil && vehicleOdometer == nil && vehicleStartCharge != nil && vehicleStopCharge == nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.ChargeState
|
||||
api.VehicleStartCharge
|
||||
}{
|
||||
Tronity: base,
|
||||
ChargeState: &decorateTronityChargeStateImpl{
|
||||
chargeState: chargeState,
|
||||
},
|
||||
VehicleStartCharge: &decorateTronityVehicleStartChargeImpl{
|
||||
vehicleStartCharge: vehicleStartCharge,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeState == nil && vehicleOdometer != nil && vehicleStartCharge != nil && vehicleStopCharge == nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.VehicleOdometer
|
||||
api.VehicleStartCharge
|
||||
}{
|
||||
Tronity: base,
|
||||
VehicleOdometer: &decorateTronityVehicleOdometerImpl{
|
||||
vehicleOdometer: vehicleOdometer,
|
||||
},
|
||||
VehicleStartCharge: &decorateTronityVehicleStartChargeImpl{
|
||||
vehicleStartCharge: vehicleStartCharge,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeState != nil && vehicleOdometer != nil && vehicleStartCharge != nil && vehicleStopCharge == nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.ChargeState
|
||||
api.VehicleOdometer
|
||||
api.VehicleStartCharge
|
||||
}{
|
||||
Tronity: base,
|
||||
ChargeState: &decorateTronityChargeStateImpl{
|
||||
chargeState: chargeState,
|
||||
},
|
||||
VehicleOdometer: &decorateTronityVehicleOdometerImpl{
|
||||
vehicleOdometer: vehicleOdometer,
|
||||
},
|
||||
VehicleStartCharge: &decorateTronityVehicleStartChargeImpl{
|
||||
vehicleStartCharge: vehicleStartCharge,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeState == nil && vehicleOdometer == nil && vehicleStartCharge == nil && vehicleStopCharge != nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.VehicleStopCharge
|
||||
}{
|
||||
Tronity: base,
|
||||
VehicleStopCharge: &decorateTronityVehicleStopChargeImpl{
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeState != nil && vehicleOdometer == nil && vehicleStartCharge == nil && vehicleStopCharge != nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.ChargeState
|
||||
api.VehicleStopCharge
|
||||
}{
|
||||
Tronity: base,
|
||||
ChargeState: &decorateTronityChargeStateImpl{
|
||||
chargeState: chargeState,
|
||||
},
|
||||
VehicleStopCharge: &decorateTronityVehicleStopChargeImpl{
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeState == nil && vehicleOdometer != nil && vehicleStartCharge == nil && vehicleStopCharge != nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.VehicleOdometer
|
||||
api.VehicleStopCharge
|
||||
}{
|
||||
Tronity: base,
|
||||
VehicleOdometer: &decorateTronityVehicleOdometerImpl{
|
||||
vehicleOdometer: vehicleOdometer,
|
||||
},
|
||||
VehicleStopCharge: &decorateTronityVehicleStopChargeImpl{
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeState != nil && vehicleOdometer != nil && vehicleStartCharge == nil && vehicleStopCharge != nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.ChargeState
|
||||
api.VehicleOdometer
|
||||
api.VehicleStopCharge
|
||||
}{
|
||||
Tronity: base,
|
||||
ChargeState: &decorateTronityChargeStateImpl{
|
||||
chargeState: chargeState,
|
||||
},
|
||||
VehicleOdometer: &decorateTronityVehicleOdometerImpl{
|
||||
vehicleOdometer: vehicleOdometer,
|
||||
},
|
||||
VehicleStopCharge: &decorateTronityVehicleStopChargeImpl{
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeState == nil && vehicleOdometer == nil && vehicleStartCharge != nil && vehicleStopCharge != nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.VehicleStartCharge
|
||||
api.VehicleStopCharge
|
||||
api.VehicleChargeController
|
||||
}{
|
||||
Tronity: base,
|
||||
VehicleStartCharge: &decorateTronityVehicleStartChargeImpl{
|
||||
VehicleChargeController: &decorateTronityVehicleChargeControllerImpl{
|
||||
vehicleStartCharge: vehicleStartCharge,
|
||||
},
|
||||
VehicleStopCharge: &decorateTronityVehicleStopChargeImpl{
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -187,18 +75,15 @@ func decorateTronity(base *Tronity, chargeState func() (api.ChargeStatus, error)
|
|||
return &struct {
|
||||
*Tronity
|
||||
api.ChargeState
|
||||
api.VehicleStartCharge
|
||||
api.VehicleStopCharge
|
||||
api.VehicleChargeController
|
||||
}{
|
||||
Tronity: base,
|
||||
ChargeState: &decorateTronityChargeStateImpl{
|
||||
chargeState: chargeState,
|
||||
},
|
||||
VehicleStartCharge: &decorateTronityVehicleStartChargeImpl{
|
||||
VehicleChargeController: &decorateTronityVehicleChargeControllerImpl{
|
||||
vehicleStartCharge: vehicleStartCharge,
|
||||
},
|
||||
VehicleStopCharge: &decorateTronityVehicleStopChargeImpl{
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -206,18 +91,15 @@ func decorateTronity(base *Tronity, chargeState func() (api.ChargeStatus, error)
|
|||
return &struct {
|
||||
*Tronity
|
||||
api.VehicleOdometer
|
||||
api.VehicleStartCharge
|
||||
api.VehicleStopCharge
|
||||
api.VehicleChargeController
|
||||
}{
|
||||
Tronity: base,
|
||||
VehicleOdometer: &decorateTronityVehicleOdometerImpl{
|
||||
vehicleOdometer: vehicleOdometer,
|
||||
},
|
||||
VehicleStartCharge: &decorateTronityVehicleStartChargeImpl{
|
||||
VehicleChargeController: &decorateTronityVehicleChargeControllerImpl{
|
||||
vehicleStartCharge: vehicleStartCharge,
|
||||
},
|
||||
VehicleStopCharge: &decorateTronityVehicleStopChargeImpl{
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -226,8 +108,7 @@ func decorateTronity(base *Tronity, chargeState func() (api.ChargeStatus, error)
|
|||
*Tronity
|
||||
api.ChargeState
|
||||
api.VehicleOdometer
|
||||
api.VehicleStartCharge
|
||||
api.VehicleStopCharge
|
||||
api.VehicleChargeController
|
||||
}{
|
||||
Tronity: base,
|
||||
ChargeState: &decorateTronityChargeStateImpl{
|
||||
|
|
@ -236,11 +117,9 @@ func decorateTronity(base *Tronity, chargeState func() (api.ChargeStatus, error)
|
|||
VehicleOdometer: &decorateTronityVehicleOdometerImpl{
|
||||
vehicleOdometer: vehicleOdometer,
|
||||
},
|
||||
VehicleStartCharge: &decorateTronityVehicleStartChargeImpl{
|
||||
VehicleChargeController: &decorateTronityVehicleChargeControllerImpl{
|
||||
vehicleStartCharge: vehicleStartCharge,
|
||||
},
|
||||
VehicleStopCharge: &decorateTronityVehicleStopChargeImpl{
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
vehicleStopCharge: vehicleStopCharge,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -264,18 +143,15 @@ func (impl *decorateTronityVehicleOdometerImpl) Odometer() (float64, error) {
|
|||
return impl.vehicleOdometer()
|
||||
}
|
||||
|
||||
type decorateTronityVehicleStartChargeImpl struct {
|
||||
type decorateTronityVehicleChargeControllerImpl struct {
|
||||
vehicleStartCharge func() error
|
||||
vehicleStopCharge func() error
|
||||
}
|
||||
|
||||
func (impl *decorateTronityVehicleStartChargeImpl) StartCharge() error {
|
||||
func (impl *decorateTronityVehicleChargeControllerImpl) StartCharge() error {
|
||||
return impl.vehicleStartCharge()
|
||||
}
|
||||
|
||||
type decorateTronityVehicleStopChargeImpl struct {
|
||||
vehicleStopCharge func() error
|
||||
}
|
||||
|
||||
func (impl *decorateTronityVehicleStopChargeImpl) StopCharge() error {
|
||||
func (impl *decorateTronityVehicleChargeControllerImpl) StopCharge() error {
|
||||
return impl.vehicleStopCharge()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,16 +170,14 @@ func (v *Provider) Position() (float64, float64, error) {
|
|||
return 0, 0, err
|
||||
}
|
||||
|
||||
var _ api.VehicleStartCharge = (*Provider)(nil)
|
||||
var _ api.VehicleChargeController = (*Provider)(nil)
|
||||
|
||||
// StartCharge implements the api.VehicleStartCharge interface
|
||||
// StartCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StartCharge() error {
|
||||
return v.action(ActionCharge, ActionChargeStart)
|
||||
}
|
||||
|
||||
var _ api.VehicleStopCharge = (*Provider)(nil)
|
||||
|
||||
// StopCharge implements the api.VehicleStopCharge interface
|
||||
// StopCharge implements the api.VehicleChargeController interface
|
||||
func (v *Provider) StopCharge() error {
|
||||
return v.action(ActionCharge, ActionChargeStop)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue