From 9bf76fca067bd062ae65c3947c761529f01d470a Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 4 Jun 2026 08:20:10 +0200 Subject: [PATCH] chore: declare static capabilities as methods (#30483) --- AGENTS.md | 1 + charger/ocpp.go | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 831e0adfd..d28bf397e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -115,6 +115,7 @@ Deep documentation on specific subsystems is available in `docs/agents/`. Load w - `_enumer.go` - generated enum code - `*_decorators.go` - generated decorator pattern implementations - Validate interface implementations: `var _ Interface = (*Type)(nil)` +- Capabilities: register via `implement.Has`/`May` only when a capability is *conditional* (runtime/config detection, e.g. `if cp.PhaseSwitching { implement.Has(...) }`). For capabilities present on every code path, declare a plain exported method plus `var _ api.Interface = (*Type)(nil)` instead. `api.Cap` resolves static methods via direct type assertion, so unconditional `implement.Has` is redundant. A type with no conditional capabilities needs neither the `implement.Caps` embed nor `implement.New()` ### Error Handling diff --git a/charger/ocpp.go b/charger/ocpp.go index 25465fe94..9a19f474e 100644 --- a/charger/ocpp.go +++ b/charger/ocpp.go @@ -128,8 +128,6 @@ func NewOCPPFromConfig(ctx context.Context, other map[string]any) (api.Charger, implement.Has(c, implement.PhaseSwitcher(c.phases1p3p)) } - implement.Has(c, implement.CurrentGetter(c.getMaxCurrent)) - return c, nil } @@ -348,9 +346,11 @@ func (c *OCPP) createTxDefaultChargingProfile(current float64) *types.ChargingPr return res } -// getMaxCurrent returns the current the charge point is set to offer. +var _ api.CurrentGetter = (*OCPP)(nil) + +// GetMaxCurrent returns the current the charge point is set to offer. // Prefers the Current.Offered measurand, falls back to the last confirmed charging profile limit. -func (c *OCPP) getMaxCurrent() (float64, error) { +func (c *OCPP) GetMaxCurrent() (float64, error) { if c.cp.HasMeasurement(types.MeasurandCurrentOffered) { if v, err := c.conn.GetMaxCurrent(); err == nil || !errors.Is(err, api.ErrNotAvailable) { return v, err