openwb-native: fix mA control (#26449)
This commit is contained in:
parent
5d4551fc7e
commit
223e70de96
2 changed files with 89 additions and 16 deletions
|
|
@ -6,12 +6,23 @@ import (
|
|||
"github.com/evcc-io/evcc/api"
|
||||
)
|
||||
|
||||
func decorateOpenWbNative(base *OpenWbNative, phaseSwitcher func(int) error, identifier func() (string, error)) api.Charger {
|
||||
func decorateOpenWbNative(base *OpenWbNative, chargerEx func(float64) error, phaseSwitcher func(int) error, identifier func() (string, error)) api.Charger {
|
||||
switch {
|
||||
case identifier == nil && phaseSwitcher == nil:
|
||||
case chargerEx == nil && identifier == nil && phaseSwitcher == nil:
|
||||
return base
|
||||
|
||||
case identifier == nil && phaseSwitcher != nil:
|
||||
case chargerEx != nil && identifier == nil && phaseSwitcher == nil:
|
||||
return &struct {
|
||||
*OpenWbNative
|
||||
api.ChargerEx
|
||||
}{
|
||||
OpenWbNative: base,
|
||||
ChargerEx: &decorateOpenWbNativeChargerExImpl{
|
||||
chargerEx: chargerEx,
|
||||
},
|
||||
}
|
||||
|
||||
case chargerEx == nil && identifier == nil && phaseSwitcher != nil:
|
||||
return &struct {
|
||||
*OpenWbNative
|
||||
api.PhaseSwitcher
|
||||
|
|
@ -22,7 +33,22 @@ func decorateOpenWbNative(base *OpenWbNative, phaseSwitcher func(int) error, ide
|
|||
},
|
||||
}
|
||||
|
||||
case identifier != nil && phaseSwitcher == nil:
|
||||
case chargerEx != nil && identifier == nil && phaseSwitcher != nil:
|
||||
return &struct {
|
||||
*OpenWbNative
|
||||
api.ChargerEx
|
||||
api.PhaseSwitcher
|
||||
}{
|
||||
OpenWbNative: base,
|
||||
ChargerEx: &decorateOpenWbNativeChargerExImpl{
|
||||
chargerEx: chargerEx,
|
||||
},
|
||||
PhaseSwitcher: &decorateOpenWbNativePhaseSwitcherImpl{
|
||||
phaseSwitcher: phaseSwitcher,
|
||||
},
|
||||
}
|
||||
|
||||
case chargerEx == nil && identifier != nil && phaseSwitcher == nil:
|
||||
return &struct {
|
||||
*OpenWbNative
|
||||
api.Identifier
|
||||
|
|
@ -33,7 +59,22 @@ func decorateOpenWbNative(base *OpenWbNative, phaseSwitcher func(int) error, ide
|
|||
},
|
||||
}
|
||||
|
||||
case identifier != nil && phaseSwitcher != nil:
|
||||
case chargerEx != nil && identifier != nil && phaseSwitcher == nil:
|
||||
return &struct {
|
||||
*OpenWbNative
|
||||
api.ChargerEx
|
||||
api.Identifier
|
||||
}{
|
||||
OpenWbNative: base,
|
||||
ChargerEx: &decorateOpenWbNativeChargerExImpl{
|
||||
chargerEx: chargerEx,
|
||||
},
|
||||
Identifier: &decorateOpenWbNativeIdentifierImpl{
|
||||
identifier: identifier,
|
||||
},
|
||||
}
|
||||
|
||||
case chargerEx == nil && identifier != nil && phaseSwitcher != nil:
|
||||
return &struct {
|
||||
*OpenWbNative
|
||||
api.Identifier
|
||||
|
|
@ -47,11 +88,38 @@ func decorateOpenWbNative(base *OpenWbNative, phaseSwitcher func(int) error, ide
|
|||
phaseSwitcher: phaseSwitcher,
|
||||
},
|
||||
}
|
||||
|
||||
case chargerEx != nil && identifier != nil && phaseSwitcher != nil:
|
||||
return &struct {
|
||||
*OpenWbNative
|
||||
api.ChargerEx
|
||||
api.Identifier
|
||||
api.PhaseSwitcher
|
||||
}{
|
||||
OpenWbNative: base,
|
||||
ChargerEx: &decorateOpenWbNativeChargerExImpl{
|
||||
chargerEx: chargerEx,
|
||||
},
|
||||
Identifier: &decorateOpenWbNativeIdentifierImpl{
|
||||
identifier: identifier,
|
||||
},
|
||||
PhaseSwitcher: &decorateOpenWbNativePhaseSwitcherImpl{
|
||||
phaseSwitcher: phaseSwitcher,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type decorateOpenWbNativeChargerExImpl struct {
|
||||
chargerEx func(float64) error
|
||||
}
|
||||
|
||||
func (impl *decorateOpenWbNativeChargerExImpl) MaxCurrentMillis(p0 float64) error {
|
||||
return impl.chargerEx(p0)
|
||||
}
|
||||
|
||||
type decorateOpenWbNativeIdentifierImpl struct {
|
||||
identifier func() (string, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func init() {
|
|||
registry.AddCtx("openwb-native", NewOpenWbNativeFromConfig)
|
||||
}
|
||||
|
||||
//go:generate go tool decorate -o openwb-native_decorators_linux.go -f decorateOpenWbNative -b *OpenWbNative -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.Identifier,Identify,func() (string, error)"
|
||||
//go:generate go tool decorate -o openwb-native_decorators_linux.go -f decorateOpenWbNative -b *OpenWbNative -r api.Charger -t "api.ChargerEx,MaxCurrentMillis,func(float64) error" -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.Identifier,Identify,func() (string, error)"
|
||||
|
||||
// NewOpenWbNativeFromConfig creates an OpenWbNative charger from generic config
|
||||
func NewOpenWbNativeFromConfig(ctx context.Context, other map[string]any) (api.Charger, error) {
|
||||
|
|
@ -57,18 +57,18 @@ func NewOpenWbNativeFromConfig(ctx context.Context, other map[string]any) (api.C
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if (cc.Connector < 1) || (cc.Connector > 2) {
|
||||
return nil, fmt.Errorf("invalid connector value: %d", cc.Connector)
|
||||
}
|
||||
if cc.CpWait < minCpWaitTime {
|
||||
return nil, fmt.Errorf("invalid cpwait value: %v, needs to be greater than %s", cc.CpWait, minCpWaitTime)
|
||||
}
|
||||
|
||||
return NewOpenWbNative(ctx, cc.URI, cc.Device, cc.Comset, cc.Baudrate, cc.Protocol(), cc.ID, cc.Phases1p3p, cc.RfId, cc.CpWait, cc.Connector)
|
||||
}
|
||||
|
||||
// NewOpenWbNative creates OpenWbNative charger
|
||||
func NewOpenWbNative(ctx context.Context, uri, device, comset string, baudrate int, proto modbus.Protocol, slaveID uint8, hasPhases1p3p bool, rfIdVidPid string, cpWait time.Duration, connector int) (api.Charger, error) {
|
||||
if (connector < 1) || (connector > 2) {
|
||||
return nil, fmt.Errorf("invalid connector value: %d", connector)
|
||||
}
|
||||
if cpWait < minCpWaitTime {
|
||||
return nil, fmt.Errorf("invalid cpwait value: %s, needs to be greater %s", cpWait.String(), minCpWaitTime)
|
||||
}
|
||||
|
||||
log := util.NewLogger("openwb-native")
|
||||
log.DEBUG.Printf("Creating OpenWB native with 3 phases %t, rfid %s, cpwait %s, connector %d", hasPhases1p3p, rfIdVidPid, cpWait.String(), connector)
|
||||
|
||||
|
|
@ -86,10 +86,15 @@ func NewOpenWbNative(ctx context.Context, uri, device, comset string, baudrate i
|
|||
}
|
||||
|
||||
var (
|
||||
phases1p3p func(int) error
|
||||
identify func() (string, error)
|
||||
phases1p3p func(int) error
|
||||
identify func() (string, error)
|
||||
maxCurrentMillis func(float64) error
|
||||
)
|
||||
|
||||
if ex, ok := evse.(api.ChargerEx); ok {
|
||||
maxCurrentMillis = ex.MaxCurrentMillis
|
||||
}
|
||||
|
||||
// configure special external hardware features
|
||||
if hasPhases1p3p {
|
||||
phases1p3p = wb.phases1p3p
|
||||
|
|
@ -114,7 +119,7 @@ func NewOpenWbNative(ctx context.Context, uri, device, comset string, baudrate i
|
|||
rpio.Pin(pin.Value().(int)).Output()
|
||||
}
|
||||
|
||||
return decorateOpenWbNative(wb, phases1p3p, identify), nil
|
||||
return decorateOpenWbNative(wb, maxCurrentMillis, phases1p3p, identify), nil
|
||||
}
|
||||
|
||||
// Status implements the api.Charger interface
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue