Fix docorating by promoting embedded type methods as capabilities (#28995)
Some checks failed
Some checks failed
This commit is contained in:
parent
3f107d1778
commit
94c2606797
65 changed files with 301 additions and 0 deletions
|
|
@ -33,6 +33,9 @@ type decorateABLeMHCapable struct {
|
|||
|
||||
func (d *decorateABLeMHCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateAlfenCapable struct {
|
|||
|
||||
func (d *decorateAlfenCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateAmperfiedCapable struct {
|
|||
|
||||
func (d *decorateAmperfiedCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@ type decorateBenderCCCapable struct {
|
|||
|
||||
func (d *decorateBenderCCCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ type decorateCfosCapable struct {
|
|||
|
||||
func (d *decorateCfosCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ type decorateCustomCapable struct {
|
|||
|
||||
func (d *decorateCustomCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateDaheimLadenCapable struct {
|
|||
|
||||
func (d *decorateDaheimLadenCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateEEBusCapable struct {
|
|||
|
||||
func (d *decorateEEBusCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateEm2GoCapable struct {
|
|||
|
||||
func (d *decorateEm2GoCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateEtekCapable struct {
|
|||
|
||||
func (d *decorateEtekCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateEVECUBECapable struct {
|
|||
|
||||
func (d *decorateEVECUBECapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ type decorateEvseDINCapable struct {
|
|||
|
||||
func (d *decorateEvseDINCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ type decorateEVSECapable struct {
|
|||
|
||||
func (d *decorateEVSECapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ type decorateGhostEEBusCapable struct {
|
|||
|
||||
func (d *decorateGhostEEBusCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateGoECapable struct {
|
|||
|
||||
func (d *decorateGoECapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ type decorateSaliaCapable struct {
|
|||
|
||||
func (d *decorateSaliaCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ type decorateHeatpumpCapable struct {
|
|||
|
||||
func (d *decorateHeatpumpCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ type decorateHomeAssistantCapable struct {
|
|||
|
||||
func (d *decorateHomeAssistantCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateInnogyCapable struct {
|
|||
|
||||
func (d *decorateInnogyCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ type decorateKebaCapable struct {
|
|||
|
||||
func (d *decorateKebaCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateKebaUdpCapable struct {
|
|||
|
||||
func (d *decorateKebaUdpCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateKSECapable struct {
|
|||
|
||||
func (d *decorateKSECapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ type decorateMennekesCompactCapable struct {
|
|||
|
||||
func (d *decorateMennekesCompactCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ type decorateNRGKickGen2Capable struct {
|
|||
|
||||
func (d *decorateNRGKickGen2Capable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ type decorateOCPPCapable struct {
|
|||
|
||||
func (d *decorateOCPPCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ type decorateOpenEVSECapable struct {
|
|||
|
||||
func (d *decorateOpenEVSECapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateOpenWB20Capable struct {
|
|||
|
||||
func (d *decorateOpenWB20Capable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateOpenWbNativeCapable struct {
|
|||
|
||||
func (d *decorateOpenWbNativeCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ type decorateOpenWBProCapable struct {
|
|||
|
||||
func (d *decorateOpenWBProCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateOpenWBCapable struct {
|
|||
|
||||
func (d *decorateOpenWBCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decoratePCECapable struct {
|
|||
|
||||
func (d *decoratePCECapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decoratePeblarCapable struct {
|
|||
|
||||
func (d *decoratePeblarCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ type decoratePhoenixCharxCapable struct {
|
|||
|
||||
func (d *decoratePhoenixCharxCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ type decoratePhoenixEMEthCapable struct {
|
|||
|
||||
func (d *decoratePhoenixEMEthCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ type decoratePhoenixEVEthCapable struct {
|
|||
|
||||
func (d *decoratePhoenixEVEthCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ type decoratePulsaresCapable struct {
|
|||
|
||||
func (d *decoratePulsaresCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateSEMPCapable struct {
|
|||
|
||||
func (d *decorateSEMPCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ type decorateSgReadyCapable struct {
|
|||
|
||||
func (d *decorateSgReadyCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateShellyCapable struct {
|
|||
|
||||
func (d *decorateShellyCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateSolaxCapable struct {
|
|||
|
||||
func (d *decorateSolaxCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateSwitchSocketCapable struct {
|
|||
|
||||
func (d *decorateSwitchSocketCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateTasmotaCapable struct {
|
|||
|
||||
func (d *decorateTasmotaCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateVaillantCapable struct {
|
|||
|
||||
func (d *decorateVaillantCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateVestelCapable struct {
|
|||
|
||||
func (d *decorateVestelCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateVictronCapable struct {
|
|||
|
||||
func (d *decorateVictronCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ type decorateWallbeCapable struct {
|
|||
|
||||
func (d *decorateWallbeCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ type decorateWarpWSCapable struct {
|
|||
|
||||
func (d *decorateWarpWSCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ type decorateWarp2Capable struct {
|
|||
|
||||
func (d *decorateWarp2Capable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ type decorateWeidmüllerCapable struct {
|
|||
|
||||
func (d *decorateWeidmüllerCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ type decorateZaptecCapable struct {
|
|||
|
||||
func (d *decorateZaptecCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ type {{.Function}}Capable struct {
|
|||
|
||||
func (d *{{.Function}}Capable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateTestCapable struct {
|
|||
|
||||
func (d *decorateTestCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
106
core/capable_test.go
Normal file
106
core/capable_test.go
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type charger struct {
|
||||
caps map[reflect.Type]any
|
||||
}
|
||||
|
||||
var _ api.Capable = (*charger)(nil)
|
||||
|
||||
func (c *charger) Capability(typ reflect.Type) (any, bool) {
|
||||
cap, ok := c.caps[typ]
|
||||
if !ok && reflect.TypeOf(c).Implements(typ) {
|
||||
return c, true
|
||||
}
|
||||
return cap, ok
|
||||
}
|
||||
|
||||
var _ api.Meter = (*charger)(nil)
|
||||
|
||||
func (c *charger) CurrentPower() (float64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var _ api.BatteryCapacity = (*charger)(nil)
|
||||
|
||||
func (c *charger) Capacity() float64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
var _ api.MeterEnergy = (*charger)(nil)
|
||||
|
||||
func (c *charger) TotalEnergy() (float64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
var _ api.Battery = (*batteryImpl)(nil)
|
||||
|
||||
type batteryImpl struct {
|
||||
soc func() (float64, error)
|
||||
}
|
||||
|
||||
func (impl *batteryImpl) Soc() (float64, error) {
|
||||
return impl.soc()
|
||||
}
|
||||
|
||||
func TestCapsWrapping(t *testing.T) {
|
||||
// type is just a shortcut for something simple that is not a meter
|
||||
var c api.BatteryCapacity
|
||||
|
||||
c = &charger{
|
||||
caps: make(map[reflect.Type]any),
|
||||
}
|
||||
|
||||
c.(*charger).caps[reflect.TypeFor[api.Battery]()] = &batteryImpl{
|
||||
soc: func() (float64, error) {
|
||||
return 0, nil
|
||||
},
|
||||
}
|
||||
|
||||
{
|
||||
_, ok := c.(api.Meter)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
{
|
||||
_, ok := c.(api.MeterEnergy)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
{
|
||||
_, ok := c.(api.Battery)
|
||||
assert.False(t, ok)
|
||||
assert.True(t, api.HasCap[api.Battery](c))
|
||||
}
|
||||
|
||||
var m api.Meter
|
||||
|
||||
if mt, ok := api.Cap[api.Meter](c); ok {
|
||||
if c, ok := c.(api.Capable); ok {
|
||||
m = &capableMeter{Meter: mt, Capable: c}
|
||||
} else {
|
||||
m = mt
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
_, ok := m.(api.MeterEnergy)
|
||||
assert.False(t, ok, "unexpected promoted energy")
|
||||
assert.True(t, api.HasCap[api.MeterEnergy](m), "missing promoted energy cap")
|
||||
|
||||
var mm any = m.(*capableMeter).Meter
|
||||
_, ok = mm.(api.MeterEnergy)
|
||||
assert.True(t, ok, "missing embedded energy")
|
||||
assert.True(t, api.HasCap[api.MeterEnergy](mm), "missing embedded energy cap")
|
||||
}
|
||||
{
|
||||
_, ok := m.(api.Battery)
|
||||
assert.False(t, ok)
|
||||
assert.True(t, api.HasCap[api.Battery](m), "missing battery cap")
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,9 @@ type decorateDsmrCapable struct {
|
|||
|
||||
func (d *decorateDsmrCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ type decorateE3dcCapable struct {
|
|||
|
||||
func (d *decorateE3dcCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ type decorateGoodWeWifiCapable struct {
|
|||
|
||||
func (d *decorateGoodWeWifiCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ type decorateLgEssCapable struct {
|
|||
|
||||
func (d *decorateLgEssCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ type decorateMeterCapable struct {
|
|||
|
||||
func (d *decorateMeterCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
@ -129,6 +132,9 @@ type decorateMeterBatteryCapable struct {
|
|||
|
||||
func (d *decorateMeterBatteryCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ type decoratePowerWallCapable struct {
|
|||
|
||||
func (d *decoratePowerWallCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,9 @@ type decorateRCTCapable struct {
|
|||
|
||||
func (d *decorateRCTCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateShellyCapable struct {
|
|||
|
||||
func (d *decorateShellyCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateTasmotaCapable struct {
|
|||
|
||||
func (d *decorateTasmotaCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ type decorateTqEmCapable struct {
|
|||
|
||||
func (d *decorateTqEmCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ type decorateTronityCapable struct {
|
|||
|
||||
func (d *decorateTronityCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,9 @@ type decorateVehicleCapable struct {
|
|||
|
||||
func (d *decorateVehicleCapable) Capability(typ reflect.Type) (any, bool) {
|
||||
c, ok := d.caps[typ]
|
||||
if !ok && reflect.TypeOf(d).Implements(typ) {
|
||||
return d, true
|
||||
}
|
||||
return c, ok
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue