Skip to content

Commit

Permalink
Loadpoint: add welcomecharge feature (#13534)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Apr 25, 2024
1 parent 846ef7b commit 1d4e695
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions api/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ const (
IntegratedDevice
Heating
Retryable
WelcomeCharge
)
12 changes: 8 additions & 4 deletions api/feature_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/coordinator/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func NewAdapter(lp loadpoint.API, c *Coordinator) API {
}
}

func (a *adapter) GetVehicles() []api.Vehicle {
return a.c.GetVehicles()
func (a *adapter) GetVehicles(availableOnly bool) []api.Vehicle {
return a.c.GetVehicles(availableOnly)
}

func (a *adapter) Owner(v api.Vehicle) loadpoint.API {
Expand Down
4 changes: 2 additions & 2 deletions core/coordinator/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

// API is the coordinator API
type API interface {
// GetVehicles returns the list of all vehicles
GetVehicles() []api.Vehicle
// GetVehicles returns the list of all vehicles, filtered by availability
GetVehicles(availableOnly bool) []api.Vehicle

// Owner returns the loadpoint that currently owns the vehicle
Owner(api.Vehicle) loadpoint.API
Expand Down
12 changes: 9 additions & 3 deletions core/coordinator/coordinator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package coordinator

import (
"slices"
"sync"

"github.com/evcc-io/evcc/api"
Expand All @@ -27,11 +26,18 @@ func New(log *util.Logger, vehicles []api.Vehicle) *Coordinator {
}

// GetVehicles returns the list of all vehicles
func (c *Coordinator) GetVehicles() []api.Vehicle {
func (c *Coordinator) GetVehicles(availableOnly bool) []api.Vehicle {
c.mu.RLock()
defer c.mu.RUnlock()

return slices.Clone(c.vehicles)
res := make([]api.Vehicle, 0, len(c.vehicles))
for _, v := range c.vehicles {
if _, tracked := c.tracked[v]; !availableOnly || availableOnly && !tracked {
res = append(res, v)
}
}

return res
}

// Owner returns the loadpoint that currently owns the vehicle
Expand Down
2 changes: 1 addition & 1 deletion core/coordinator/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewDummy() API {
return new(dummy)
}

func (a *dummy) GetVehicles() []api.Vehicle {
func (a *dummy) GetVehicles(_ bool) []api.Vehicle {
return nil
}

Expand Down
16 changes: 16 additions & 0 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"reflect"
"slices"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -470,6 +471,9 @@ func (lp *Loadpoint) evVehicleConnectHandler() {
lp.socEstimator.Reset()
}

// get pv mode before vehicle defaults are applied
pvMode := lp.GetMode() == api.ModePV || lp.GetMode() == api.ModeMinPV

// set default or start detection
if !lp.chargerHasFeature(api.IntegratedDevice) {
lp.vehicleDefaultOrDetect()
Expand All @@ -478,6 +482,18 @@ func (lp *Loadpoint) evVehicleConnectHandler() {
// immediately allow pv mode activity
lp.elapsePVTimer()

// Enable charging on connect if any available vehicle requires it. We're using the PV timer
// to disable after the welcome, hence this must be placed after elapsePVTimer.
// TODO check is this doesn't conflict with vehicle defaults like mode: off
if pvMode {
for _, v := range lp.availableVehicles() {
if slices.Contains(v.Features(), api.WelcomeCharge) {
lp.setLimit(lp.effectiveMinCurrent())
break
}
}
}

// create charging session
lp.createSession()
}
Expand Down
10 changes: 9 additions & 1 deletion core/loadpoint_vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ const (
vehicleDetectDuration = 10 * time.Minute
)

// availableVehicles is the slice of vehicles from the coordinator that are available
func (lp *Loadpoint) availableVehicles() []api.Vehicle {
if lp.coordinator == nil {
return nil
}
return lp.coordinator.GetVehicles(true)
}

// coordinatedVehicles is the slice of vehicles from the coordinator
func (lp *Loadpoint) coordinatedVehicles() []api.Vehicle {
if lp.coordinator == nil {
return nil
}
return lp.coordinator.GetVehicles()
return lp.coordinator.GetVehicles(false)
}

// setVehicleIdentifier updated the vehicle id as read from the charger
Expand Down

0 comments on commit 1d4e695

Please sign in to comment.