Disable detection by status for vehicles with defined id on id-capable chargers (#4111)
This commit is contained in:
parent
d1211cb13a
commit
58ca0b16dc
6 changed files with 23 additions and 13 deletions
|
|
@ -31,6 +31,7 @@ func (a *adapter) Release(v api.Vehicle) {
|
|||
a.c.release(v)
|
||||
}
|
||||
|
||||
func (a *adapter) IdentifyVehicleByStatus() api.Vehicle {
|
||||
return a.c.identifyVehicleByStatus(a.lp)
|
||||
func (a *adapter) IdentifyVehicleByStatus(includeIdCapable bool) api.Vehicle {
|
||||
available := a.c.availableDetectibleVehicles(a.lp, includeIdCapable)
|
||||
return a.c.identifyVehicleByStatus(available)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ type API interface {
|
|||
GetVehicles() []api.Vehicle
|
||||
Acquire(api.Vehicle)
|
||||
Release(api.Vehicle)
|
||||
IdentifyVehicleByStatus() api.Vehicle
|
||||
IdentifyVehicleByStatus(includeIdCapable bool) api.Vehicle
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,13 +39,18 @@ 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) []api.Vehicle {
|
||||
func (c *Coordinator) availableDetectibleVehicles(owner loadpoint.API, includeIdCapable bool) []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 {
|
||||
res = append(res, vv)
|
||||
// no identifiers configured or identifiers ignored
|
||||
if includeIdCapable || len(vv.Identifiers()) == 0 {
|
||||
res = append(res, vv)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -54,9 +59,7 @@ func (c *Coordinator) availableDetectibleVehicles(owner loadpoint.API) []api.Veh
|
|||
}
|
||||
|
||||
// identifyVehicleByStatus finds active vehicle by charge state
|
||||
func (c *Coordinator) identifyVehicleByStatus(owner loadpoint.API) api.Vehicle {
|
||||
available := c.availableDetectibleVehicles(owner)
|
||||
|
||||
func (c *Coordinator) identifyVehicleByStatus(available []api.Vehicle) api.Vehicle {
|
||||
var res api.Vehicle
|
||||
for _, vehicle := range available {
|
||||
if vs, ok := vehicle.(api.ChargeState); ok {
|
||||
|
|
|
|||
|
|
@ -38,6 +38,11 @@ func TestVehicleDetectByStatus(t *testing.T) {
|
|||
log := util.NewLogger("foo")
|
||||
vehicles := []api.Vehicle{v1, v2}
|
||||
|
||||
v1.MockVehicle.EXPECT().Title().Return("v1").AnyTimes()
|
||||
v2.MockVehicle.EXPECT().Title().Return("v2").AnyTimes()
|
||||
v1.MockVehicle.EXPECT().Identifiers().Return(nil).AnyTimes()
|
||||
v2.MockVehicle.EXPECT().Identifiers().Return([]string{"it's me"}).AnyTimes()
|
||||
|
||||
var lp loadpoint.API
|
||||
c := New(log, vehicles)
|
||||
|
||||
|
|
@ -46,10 +51,9 @@ func TestVehicleDetectByStatus(t *testing.T) {
|
|||
|
||||
v1.MockChargeState.EXPECT().Status().Return(tc.v1, nil)
|
||||
v2.MockChargeState.EXPECT().Status().Return(tc.v2, nil)
|
||||
v1.MockVehicle.EXPECT().Title().Return("v1").AnyTimes()
|
||||
v2.MockVehicle.EXPECT().Title().Return("v2").AnyTimes()
|
||||
|
||||
res := c.identifyVehicleByStatus(lp)
|
||||
available := c.availableDetectibleVehicles(lp, true) // include id-able vehicles
|
||||
res := c.identifyVehicleByStatus(available)
|
||||
if tc.res != res {
|
||||
t.Errorf("expected %v, got %v", tc.res, res)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,6 @@ func (a *dummy) Acquire(v api.Vehicle) {}
|
|||
|
||||
func (a *dummy) Release(v api.Vehicle) {}
|
||||
|
||||
func (a *dummy) IdentifyVehicleByStatus() api.Vehicle {
|
||||
func (a *dummy) IdentifyVehicleByStatus(includeIdCapable bool) api.Vehicle {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -908,7 +908,9 @@ func (lp *LoadPoint) identifyVehicleByStatus() {
|
|||
return
|
||||
}
|
||||
|
||||
if vehicle := lp.coordinator.IdentifyVehicleByStatus(); vehicle != nil {
|
||||
_, ok := lp.charger.(api.Identifier)
|
||||
|
||||
if vehicle := lp.coordinator.IdentifyVehicleByStatus(!ok); vehicle != nil {
|
||||
lp.setActiveVehicle(vehicle)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue