Replace combinatorial decorators with capability registry (BC) (#28565)
This commit is contained in:
parent
33d2de24c1
commit
00967eb57e
101 changed files with 2416 additions and 44670 deletions
|
|
@ -218,7 +218,7 @@ type testResult = struct {
|
|||
}
|
||||
|
||||
func hasFeature(instance any, f api.Feature) bool {
|
||||
fd, ok := instance.(api.FeatureDescriber)
|
||||
fd, ok := api.Cap[api.FeatureDescriber](instance)
|
||||
return ok && slices.Contains(fd.Features(), f)
|
||||
}
|
||||
|
||||
|
|
@ -238,17 +238,17 @@ func testInstance(instance any) map[string]testResult {
|
|||
res[key] = tr
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.Meter); ok {
|
||||
if dev, ok := api.Cap[api.Meter](instance); ok {
|
||||
val, err := dev.CurrentPower()
|
||||
makeResult("power", val, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.MeterEnergy); ok {
|
||||
if dev, ok := api.Cap[api.MeterEnergy](instance); ok {
|
||||
val, err := dev.TotalEnergy()
|
||||
makeResult("energy", val, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.Battery); ok {
|
||||
if dev, ok := api.Cap[api.Battery](instance); ok {
|
||||
val, err := dev.Soc()
|
||||
key := "soc"
|
||||
if hasFeature(instance, api.Heating) {
|
||||
|
|
@ -257,51 +257,51 @@ func testInstance(instance any) map[string]testResult {
|
|||
makeResult(key, val, err)
|
||||
}
|
||||
|
||||
if _, ok := instance.(api.BatteryController); ok {
|
||||
if api.HasCap[api.BatteryController](instance) {
|
||||
makeResult("controllable", true, nil)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.VehicleOdometer); ok {
|
||||
if dev, ok := api.Cap[api.VehicleOdometer](instance); ok {
|
||||
val, err := dev.Odometer()
|
||||
makeResult("odometer", val, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.BatteryCapacity); ok {
|
||||
if dev, ok := api.Cap[api.BatteryCapacity](instance); ok {
|
||||
val := dev.Capacity()
|
||||
makeResult("capacity", val, nil)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.PhaseCurrents); ok {
|
||||
if dev, ok := api.Cap[api.PhaseCurrents](instance); ok {
|
||||
i1, i2, i3, err := dev.Currents()
|
||||
makeResult("phaseCurrents", []float64{i1, i2, i3}, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.PhaseVoltages); ok {
|
||||
if dev, ok := api.Cap[api.PhaseVoltages](instance); ok {
|
||||
u1, u2, u3, err := dev.Voltages()
|
||||
makeResult("phaseVoltages", []float64{u1, u2, u3}, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.PhasePowers); ok {
|
||||
if dev, ok := api.Cap[api.PhasePowers](instance); ok {
|
||||
p1, p2, p3, err := dev.Powers()
|
||||
makeResult("phasePowers", []float64{p1, p2, p3}, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.ChargeState); ok {
|
||||
if dev, ok := api.Cap[api.ChargeState](instance); ok {
|
||||
val, err := dev.Status()
|
||||
makeResult("chargeStatus", val, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.Charger); ok {
|
||||
if dev, ok := api.Cap[api.Charger](instance); ok {
|
||||
val, err := dev.Enabled()
|
||||
makeResult("enabled", val, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.ChargeRater); ok {
|
||||
if dev, ok := api.Cap[api.ChargeRater](instance); ok {
|
||||
val, err := dev.ChargedEnergy()
|
||||
makeResult("chargedEnergy", val, err)
|
||||
}
|
||||
|
||||
if _, ok := instance.(api.PhaseSwitcher); ok {
|
||||
if api.HasCap[api.PhaseSwitcher](instance) {
|
||||
makeResult("phases1p3p", true, nil)
|
||||
}
|
||||
|
||||
|
|
@ -313,20 +313,20 @@ func testInstance(instance any) map[string]testResult {
|
|||
makeResult("integratedDevice", true, nil)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.IconDescriber); ok && dev.Icon() != "" {
|
||||
if dev, ok := api.Cap[api.IconDescriber](instance); ok && dev.Icon() != "" {
|
||||
makeResult("icon", dev.Icon(), nil)
|
||||
}
|
||||
|
||||
if cc, ok := instance.(api.PhaseDescriber); ok && cc.Phases() == 1 {
|
||||
if cc, ok := api.Cap[api.PhaseDescriber](instance); ok && cc.Phases() == 1 {
|
||||
makeResult("singlePhase", true, nil)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.VehicleRange); ok {
|
||||
if dev, ok := api.Cap[api.VehicleRange](instance); ok {
|
||||
val, err := dev.Range()
|
||||
makeResult("range", val, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.SocLimiter); ok {
|
||||
if dev, ok := api.Cap[api.SocLimiter](instance); ok {
|
||||
val, err := dev.GetLimitSoc()
|
||||
key := "vehicleLimitSoc"
|
||||
if hasFeature(instance, api.Heating) {
|
||||
|
|
@ -335,17 +335,17 @@ func testInstance(instance any) map[string]testResult {
|
|||
makeResult(key, val, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.Dimmer); ok {
|
||||
if dev, ok := api.Cap[api.Dimmer](instance); ok {
|
||||
val, err := dev.Dimmed()
|
||||
makeResult("dimmed", val, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.Identifier); ok {
|
||||
if dev, ok := api.Cap[api.Identifier](instance); ok {
|
||||
val, err := dev.Identify()
|
||||
makeResult("identifier", val, err)
|
||||
}
|
||||
|
||||
if dev, ok := instance.(api.Tariff); ok {
|
||||
if dev, ok := api.Cap[api.Tariff](instance); ok {
|
||||
rates, err := dev.Rates()
|
||||
|
||||
// Determine field names based on tariff type
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func csvResult(ctx context.Context, w http.ResponseWriter, res any, filename str
|
|||
w.Header().Set("Content-Type", "text/csv")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="`+filename+`.csv"`)
|
||||
|
||||
if ww, ok := res.(api.CsvWriter); ok {
|
||||
if ww, ok := api.Cap[api.CsvWriter](res); ok {
|
||||
_ = ww.WriteCsv(ctx, w)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue