Skip to content

Commit a1085a3

Browse files
andigtoeklk
authored andcommitted
chore: declare static capabilities as methods (evcc-io#30483)
1 parent 1ce687e commit a1085a3

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Deep documentation on specific subsystems is available in `docs/agents/`. Load w
115115
- `_enumer.go` - generated enum code
116116
- `*_decorators.go` - generated decorator pattern implementations
117117
- Validate interface implementations: `var _ Interface = (*Type)(nil)`
118+
- 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()`
118119

119120
### Error Handling
120121

charger/ocpp.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ func NewOCPPFromConfig(ctx context.Context, other map[string]any) (api.Charger,
128128
implement.Has(c, implement.PhaseSwitcher(c.phases1p3p))
129129
}
130130

131-
implement.Has(c, implement.CurrentGetter(c.getMaxCurrent))
132-
133131
return c, nil
134132
}
135133

@@ -348,9 +346,11 @@ func (c *OCPP) createTxDefaultChargingProfile(current float64) *types.ChargingPr
348346
return res
349347
}
350348

351-
// getMaxCurrent returns the current the charge point is set to offer.
349+
var _ api.CurrentGetter = (*OCPP)(nil)
350+
351+
// GetMaxCurrent returns the current the charge point is set to offer.
352352
// Prefers the Current.Offered measurand, falls back to the last confirmed charging profile limit.
353-
func (c *OCPP) getMaxCurrent() (float64, error) {
353+
func (c *OCPP) GetMaxCurrent() (float64, error) {
354354
if c.cp.HasMeasurement(types.MeasurandCurrentOffered) {
355355
if v, err := c.conn.GetMaxCurrent(); err == nil || !errors.Is(err, api.ErrNotAvailable) {
356356
return v, err

0 commit comments

Comments
 (0)