Vehicle: reduce decorators (BC) (#26866)
This commit is contained in:
parent
6a9f860cc1
commit
2f5f2f1e9f
5 changed files with 99 additions and 8478 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"go/format"
|
||||
"io"
|
||||
"maps"
|
||||
"os"
|
||||
"reflect"
|
||||
"slices"
|
||||
|
|
@ -72,6 +73,9 @@ var a struct {
|
|||
api.BatterySocLimiter
|
||||
api.BatteryPowerLimiter
|
||||
|
||||
// vehicle
|
||||
api.ChargeState
|
||||
api.ChargeController
|
||||
api.CurrentController
|
||||
api.CurrentGetter
|
||||
}
|
||||
|
|
@ -85,6 +89,7 @@ var dependents = map[string][]string{
|
|||
typ(&a.PhaseCurrents): {typ(&a.PhasePowers)}, // phase powers are only used to determine currents sign
|
||||
typ(&a.PhaseSwitcher): {typ(&a.PhaseGetter)},
|
||||
typ(&a.Battery): {typ(&a.BatteryCapacity), typ(&a.SocLimiter), typ(&a.BatteryController), typ(&a.BatterySocLimiter), typ(&a.BatteryPowerLimiter)},
|
||||
typ(&a.ChargeState): {typ(&a.ChargeController), typ(&a.CurrentController)},
|
||||
typ(&a.CurrentController): {typ(&a.CurrentGetter)},
|
||||
}
|
||||
|
||||
|
|
@ -190,9 +195,13 @@ func generate(out io.Writer, functionName, baseType string, dynamicTypes ...dyna
|
|||
}
|
||||
|
||||
validCombos := make([][]string, 0)
|
||||
sortedDependents := slices.Sorted(maps.Keys(dependents))
|
||||
|
||||
COMBO:
|
||||
for _, c := range combinations.All(combos) {
|
||||
for master, details := range dependents {
|
||||
// order the cases for generation
|
||||
for _, master := range sortedDependents {
|
||||
details := dependents[master]
|
||||
// prune combinations where ...
|
||||
// - master is part of the decorators
|
||||
// - master is not part of the currently evaluated combination
|
||||
|
|
@ -232,6 +241,8 @@ COMBO:
|
|||
Combinations: validCombos,
|
||||
}
|
||||
|
||||
// fmt.Fprintf(out, "// combo %v\n\n", validCombos)
|
||||
|
||||
return tmpl.Execute(out, vars)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ type EnergyGuard struct {
|
|||
}
|
||||
|
||||
type EEBus struct {
|
||||
service eebusapi.ServiceInterface
|
||||
service eebusapi.ServiceInterface
|
||||
remoteServices []shipapi.RemoteService
|
||||
|
||||
cem CustomerEnergyManagement
|
||||
cs ControllableSystem
|
||||
|
|
@ -271,6 +272,12 @@ func (c *EEBus) EnergyGuard() *EnergyGuard {
|
|||
return &c.eg
|
||||
}
|
||||
|
||||
func (c *EEBus) RemoteServices() []shipapi.RemoteService {
|
||||
c.mux.Lock()
|
||||
defer c.mux.Unlock()
|
||||
return c.remoteServices
|
||||
}
|
||||
|
||||
func (c *EEBus) Run() {
|
||||
c.service.Start()
|
||||
}
|
||||
|
|
@ -321,6 +328,9 @@ func (c *EEBus) RemoteSKIDisconnected(service eebusapi.ServiceInterface, ski str
|
|||
// this is needed to provide an UI for pairing with other devices
|
||||
// if not all incoming pairing requests should be accepted
|
||||
func (c *EEBus) VisibleRemoteServicesUpdated(service eebusapi.ServiceInterface, entries []shipapi.RemoteService) {
|
||||
c.mux.Lock()
|
||||
defer c.mux.Unlock()
|
||||
c.remoteServices = slices.Clone(entries)
|
||||
}
|
||||
|
||||
// Provides the SHIP ID the remote service reported during the handshake process
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
func decorateTronity(base *Tronity, chargeState func() (api.ChargeStatus, error), vehicleOdometer func() (float64, error), chargeController func(bool) error) api.Vehicle {
|
||||
switch {
|
||||
case chargeController == nil && chargeState == nil && vehicleOdometer == nil:
|
||||
case chargeState == nil && vehicleOdometer == nil:
|
||||
return base
|
||||
|
||||
case chargeController == nil && chargeState != nil && vehicleOdometer == nil:
|
||||
|
|
@ -22,7 +22,7 @@ func decorateTronity(base *Tronity, chargeState func() (api.ChargeStatus, error)
|
|||
},
|
||||
}
|
||||
|
||||
case chargeController == nil && chargeState == nil && vehicleOdometer != nil:
|
||||
case chargeState == nil && vehicleOdometer != nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.VehicleOdometer
|
||||
|
|
@ -48,17 +48,6 @@ func decorateTronity(base *Tronity, chargeState func() (api.ChargeStatus, error)
|
|||
},
|
||||
}
|
||||
|
||||
case chargeController != nil && chargeState == nil && vehicleOdometer == nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.ChargeController
|
||||
}{
|
||||
Tronity: base,
|
||||
ChargeController: &decorateTronityChargeControllerImpl{
|
||||
chargeController: chargeController,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeController != nil && chargeState != nil && vehicleOdometer == nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
|
|
@ -74,21 +63,6 @@ func decorateTronity(base *Tronity, chargeState func() (api.ChargeStatus, error)
|
|||
},
|
||||
}
|
||||
|
||||
case chargeController != nil && chargeState == nil && vehicleOdometer != nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
api.ChargeController
|
||||
api.VehicleOdometer
|
||||
}{
|
||||
Tronity: base,
|
||||
ChargeController: &decorateTronityChargeControllerImpl{
|
||||
chargeController: chargeController,
|
||||
},
|
||||
VehicleOdometer: &decorateTronityVehicleOdometerImpl{
|
||||
vehicleOdometer: vehicleOdometer,
|
||||
},
|
||||
}
|
||||
|
||||
case chargeController != nil && chargeState != nil && vehicleOdometer != nil:
|
||||
return &struct {
|
||||
*Tronity
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package vehicle
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
|
|
@ -139,6 +140,15 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]any) (api.V
|
|||
return nil, fmt.Errorf("chargeEnable: %w", err)
|
||||
}
|
||||
|
||||
switch {
|
||||
case getMaxCurrent == nil && maxCurrent != nil:
|
||||
return nil, errors.New("cannot have current without current control")
|
||||
case status == nil && maxCurrent != nil:
|
||||
return nil, errors.New("cannot have current control without status")
|
||||
case status == nil && chargeEnable != nil:
|
||||
return nil, errors.New("cannot have charge control without status")
|
||||
}
|
||||
|
||||
return decorateVehicle(v, limitSoc, status, rng, odo, climater, maxCurrent, getMaxCurrent, finishTime, wakeup, chargeEnable), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue