chore: declare static capabilities as methods (#30483)

This commit is contained in:
andig 2026-06-04 08:20:10 +02:00 • committed by GitHub
parent e34459a73f
commit 9bf76fca06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View file

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

View file

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