diff --git a/charger/openwb-2.0.go b/charger/openwb-2.0.go index e182a8d6e..bf24a16e1 100644 --- a/charger/openwb-2.0.go +++ b/charger/openwb-2.0.go @@ -38,6 +38,8 @@ func init() { // https://openwb.de/main/wp-content/uploads/2023/10/ModbusTCP-openWB-series2-Pro-1.pdf +//go:generate go run ../cmd/tools/decorate.go -f decorateOpenWB20 -b *OpenWB20 -r api.Charger -t "api.Identifier,Identify,func() (string, error)" + // NewOpenWB20FromConfig creates a OpenWB20 charger from generic config func NewOpenWB20FromConfig(other map[string]interface{}) (api.Charger, error) { cc := modbus.TcpSettings{ @@ -48,7 +50,17 @@ func NewOpenWB20FromConfig(other map[string]interface{}) (api.Charger, error) { return nil, err } - return NewOpenWB20(cc.URI, cc.ID) + wb, err := NewOpenWB20(cc.URI, cc.ID) + if err != nil { + return nil, err + } + + var identify func() (string, error) + if _, err := wb.identify(); err == nil { + identify = wb.identify + } + + return decorateOpenWB20(wb, identify), nil } // NewOpenWB20 creates OpenWB20 charger @@ -180,10 +192,8 @@ func (wb *OpenWB20) WakeUp() error { return err } -var _ api.Identifier = (*OpenWB20)(nil) - // Identify implements the api.Identifier interface -func (wb *OpenWB20) Identify() (string, error) { +func (wb *OpenWB20) identify() (string, error) { b, err := wb.conn.ReadInputRegisters(openwbRegRfid, 10) if err != nil { return "", err diff --git a/charger/openwb-2.0_decorators.go b/charger/openwb-2.0_decorators.go new file mode 100644 index 000000000..4887e8dbe --- /dev/null +++ b/charger/openwb-2.0_decorators.go @@ -0,0 +1,35 @@ +package charger + +// Code generated by github.com/evcc-io/evcc/cmd/tools/decorate.go. DO NOT EDIT. + +import ( + "github.com/evcc-io/evcc/api" +) + +func decorateOpenWB20(base *OpenWB20, identifier func() (string, error)) api.Charger { + switch { + case identifier == nil: + return base + + case identifier != nil: + return &struct { + *OpenWB20 + api.Identifier + }{ + OpenWB20: base, + Identifier: &decorateOpenWB20IdentifierImpl{ + identifier: identifier, + }, + } + } + + return nil +} + +type decorateOpenWB20IdentifierImpl struct { + identifier func() (string, error) +} + +func (impl *decorateOpenWB20IdentifierImpl) Identify() (string, error) { + return impl.identifier() +}