Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions charger/daheimladen-mb.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,38 @@ const (
dlRegChargeControl = 93 // Uint16 WR ENUM
dlRegChargeCmd = 95 // Uint16 WR ENUM
dlRegVoltages = 108 // 3xUint32 RO 0.1V

// PRO only
dlRegPhaseSwitchState = 184
dlRegPhaseSwitchControl = 186
)

func init() {
registry.AddCtx("daheimladen-mb", NewDaheimLadenMBFromConfig)
}

//go:generate go tool decorate -f decorateDaheimLaden -b *DaheimLadenMB -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) error" -t "api.PhaseGetter,GetPhases,func() (int, error)"

// NewDaheimLadenMBFromConfig creates a DaheimLadenMB charger from generic config
func NewDaheimLadenMBFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
cc := modbus.TcpSettings{
ID: 255,
cc := struct {
modbus.TcpSettings `mapstructure:",squash"`
Phases1p3p bool
}{
TcpSettings: modbus.TcpSettings{
ID: 255,
},
}

if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}

return NewDaheimLadenMB(ctx, cc.URI, cc.ID)
return NewDaheimLadenMB(ctx, cc.URI, cc.ID, cc.Phases1p3p)
}

// NewDaheimLadenMB creates DaheimLadenMB charger
func NewDaheimLadenMB(ctx context.Context, uri string, id uint8) (api.Charger, error) {
func NewDaheimLadenMB(ctx context.Context, uri string, id uint8, phases bool) (api.Charger, error) {
conn, err := modbus.NewConnection(ctx, uri, "", "", 0, modbus.Tcp, id)
if err != nil {
return nil, err
Expand Down Expand Up @@ -105,7 +116,14 @@ func NewDaheimLadenMB(ctx context.Context, uri string, id uint8) (api.Charger, e
go wb.heartbeat(ctx, time.Duration(u)*time.Second/2)
}

return wb, err
var phases1p3p func(int) error
var phasesG func() (int, error)
if phases {
phases1p3p = wb.phases1p3p
phasesG = wb.getPhases
}

return decorateDaheimLaden(wb, phases1p3p, phasesG), nil
}

func (wb *DaheimLadenMB) heartbeat(ctx context.Context, timeout time.Duration) {
Expand Down Expand Up @@ -256,6 +274,25 @@ func (wb *DaheimLadenMB) Voltages() (float64, float64, float64, error) {
return wb.getPhaseValues(dlRegVoltages)
}

// phases1p3p implements the api.PhaseSwitcher interface
func (wb *DaheimLadenMB) phases1p3p(phases int) error {
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, uint16(phases))

_, err := wb.conn.WriteMultipleRegisters(dlRegPhaseSwitchControl, 1, b)
return err
}

// getPhases implements the api.PhaseGetter interface
func (wb *DaheimLadenMB) getPhases() (int, error) {
b, err := wb.conn.ReadHoldingRegisters(dlRegPhaseSwitchState, 1)
if err != nil {
return 0, err
}

return int(binary.BigEndian.Uint16(b)), nil
}

var _ api.Diagnosis = (*DaheimLadenMB)(nil)

// Diagnose implements the api.Diagnosis interface
Expand Down
58 changes: 58 additions & 0 deletions charger/daheimladen-mb_decorators.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/definition/charger/daheimladen-mb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ template: daheimladen-mb
products:
- brand: DaheimLaden
description:
generic: Wallbox
generic: Smart/Touch
requirements:
description:
de: Die Wallbox muss über eine aktuelle Firmware mit Modbus-Unterstützung verfügen. In den Einstellungen muss "Nachladen" (Smart) bzw. "RSDA" (Touch) aktiviert sein
Expand Down
14 changes: 14 additions & 0 deletions templates/definition/charger/daheimladen-pro.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
template: daheimladen-pro
products:
- brand: DaheimLaden
description:
generic: Pro
capabilities: ["1p3p"]
params:
- name: host
- name: port
default: 502
render: |
type: daheimladen-mb
uri: {{ .host }}:{{ .port }}
phases1p3p: true
Loading