Simplify vehicle identification (#5491)

This commit is contained in:
andig 2022-12-19 17:20:28 +01:00 • committed by GitHub
parent a7a713e276
commit 4577971978
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 21 deletions

View file

@ -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)
}

View file

@ -7,5 +7,5 @@ type API interface {
GetVehicles() []api.Vehicle
Acquire(api.Vehicle)
Release(api.Vehicle)
IdentifyVehicleByStatus(includeIdCapable bool) api.Vehicle
IdentifyVehicleByStatus() api.Vehicle
}

View file

@ -39,7 +39,7 @@ 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 {
@ -47,10 +47,7 @@ func (c *Coordinator) availableDetectibleVehicles(owner loadpoint.API, includeId
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)
}
}
}

View file

@ -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)

View file

@ -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
}

View file

@ -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