Skip to content

Commit

Permalink
Merge pull request #976 from andig/feature/charge-stop
Browse files Browse the repository at this point in the history
Tesla: add start/stop charge api
  • Loading branch information
andig authored May 9, 2021
2 parents fa527df + 9da3f0d commit ee3a7ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,8 @@ type VehicleClimater interface {
type VehicleStartCharge interface {
StartCharge() error
}

// VehicleStopCharge stops the charging session on the vehicle side
type VehicleStopCharge interface {
StopCharge() error
}
7 changes: 7 additions & 0 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,13 @@ func (lp *LoadPoint) setLimit(chargeCurrent float64, force bool) (err error) {
return nil
}

// sleep vehicle
if car, ok := lp.vehicle.(api.VehicleStopCharge); !enabled && ok {
if err := car.StopCharge(); err != nil {
lp.log.ERROR.Printf("vehicle remote charge stop: %v", err)
}
}

lp.log.DEBUG.Printf("charger %s", status[enabled])
if err = lp.charger.Enable(enabled); err == nil {
lp.enabled = enabled
Expand Down
14 changes: 14 additions & 0 deletions internal/vehicle/tesla.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,17 @@ func (v *Tesla) Climater() (active bool, outsideTemp float64, targetTemp float64

return false, 0, 0, api.ErrNotAvailable
}

var _ api.VehicleStartCharge = (*Tesla)(nil)

// StartCharge implements the api.VehicleStartCharge interface
func (v *Tesla) StartCharge() error {
return v.vehicle.StartCharging()
}

var _ api.VehicleStopCharge = (*Tesla)(nil)

// StopCharge implements the api.VehicleStopCharge interface
func (v *Tesla) StopCharge() error {
return v.vehicle.StopCharging()
}

0 comments on commit ee3a7ff

Please sign in to comment.