Skip to content

Commit

Permalink
Simplify vehicle identification (evcc-io#5491)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Dec 19, 2022
1 parent a7a713e commit 4577971
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 21 deletions.
4 changes: 2 additions & 2 deletions core/coordinator/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (a *adapter) Release(v api.Vehicle) {
a.c.release(v)
}

func (a *adapter) IdentifyVehicleByStatus(includeIdCapable bool) api.Vehicle {
available := a.c.availableDetectibleVehicles(a.lp, includeIdCapable)
func (a *adapter) IdentifyVehicleByStatus() api.Vehicle {
available := a.c.availableDetectibleVehicles(a.lp)
return a.c.identifyVehicleByStatus(available)
}
2 changes: 1 addition & 1 deletion core/coordinator/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ type API interface {
GetVehicles() []api.Vehicle
Acquire(api.Vehicle)
Release(api.Vehicle)
IdentifyVehicleByStatus(includeIdCapable bool) api.Vehicle
IdentifyVehicleByStatus() api.Vehicle
}
7 changes: 2 additions & 5 deletions core/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@ func (c *Coordinator) release(vehicle api.Vehicle) {

// availableDetectibleVehicles is the list of vehicles that are currently not
// associated to another loadpoint and have a status api that allows for detection
func (c *Coordinator) availableDetectibleVehicles(owner loadpoint.API, includeIdCapable bool) []api.Vehicle {
func (c *Coordinator) availableDetectibleVehicles(owner loadpoint.API) []api.Vehicle {
var res []api.Vehicle

for _, vv := range c.vehicles {
// status api available
if _, ok := vv.(api.ChargeState); ok {
// available or associated to current loadpoint
if o, ok := c.tracked[vv]; o == owner || !ok {
// no identifiers configured or identifiers ignored
if includeIdCapable || len(vv.Identifiers()) == 0 {
res = append(res, vv)
}
res = append(res, vv)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/coordinator/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestVehicleDetectByStatus(t *testing.T) {
v1.MockChargeState.EXPECT().Status().Return(tc.v1, nil)
v2.MockChargeState.EXPECT().Status().Return(tc.v2, nil)

available := c.availableDetectibleVehicles(lp, true) // include id-able vehicles
available := c.availableDetectibleVehicles(lp) // include id-able vehicles
res := c.identifyVehicleByStatus(available)
if tc.res != res {
t.Errorf("expected %v, got %v", tc.res, res)
Expand Down
2 changes: 1 addition & 1 deletion core/coordinator/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ func (a *dummy) Acquire(v api.Vehicle) {}

func (a *dummy) Release(v api.Vehicle) {}

func (a *dummy) IdentifyVehicleByStatus(includeIdCapable bool) api.Vehicle {
func (a *dummy) IdentifyVehicleByStatus() api.Vehicle {
return nil
}
12 changes: 1 addition & 11 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,7 @@ func (lp *LoadPoint) identifyVehicleByStatus() {
return
}

// decide if id-able vehicles should be included https://github.com/evcc-io/evcc/pull/5469
var ignoreIdCapable bool
if identifier, ok := lp.charger.(api.Identifier); ok {
id, err := identifier.Identify()
if err != nil {
lp.log.ERROR.Println("charger vehicle id:", err)
}
ignoreIdCapable = id != ""
}

if vehicle := lp.coordinator.IdentifyVehicleByStatus(!ignoreIdCapable); vehicle != nil {
if vehicle := lp.coordinator.IdentifyVehicleByStatus(); vehicle != nil {
lp.stopVehicleDetection()
lp.setActiveVehicle(vehicle)
return
Expand Down

0 comments on commit 4577971

Please sign in to comment.