Skip to content

Commit

Permalink
Vestel: add phase switching (#18911)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Feb 17, 2025
1 parent bc219c8 commit 3365c84
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
32 changes: 30 additions & 2 deletions charger/vestel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
vestelRegBrand = 190 // 10
vestelRegModel = 210 // 5
vestelRegFirmware = 230 // 50
vestelRegNumberPhases = 404
vestelRegPhasesSwitch = 405
vestelRegChargeStatus = 1001
vestelRegCableStatus = 1004
vestelRegChargeTime = 1508
Expand Down Expand Up @@ -64,6 +66,8 @@ func init() {
registry.AddCtx("vestel", NewVestelFromConfig)
}

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

// NewVestelFromConfig creates a Vestel charger from generic config
func NewVestelFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
cc := modbus.TcpSettings{
Expand All @@ -78,7 +82,7 @@ func NewVestelFromConfig(ctx context.Context, other map[string]interface{}) (api
}

// NewVestel creates a Vestel charger
func NewVestel(ctx context.Context, uri string, id uint8) (*Vestel, error) {
func NewVestel(ctx context.Context, uri string, id uint8) (api.Charger, error) {
conn, err := modbus.NewConnection(uri, "", "", 0, modbus.Tcp, id)
if err != nil {
return nil, err
Expand All @@ -97,6 +101,15 @@ func NewVestel(ctx context.Context, uri string, id uint8) (*Vestel, error) {
current: 6,
}

var (
phasesS func(int) error
phasesG func() (int, error)
)
if b, err := wb.conn.ReadHoldingRegisters(vestelRegNumberPhases, 1); err == nil && binary.BigEndian.Uint16(b) == 3 {
phasesS = wb.phases1p3p
phasesG = wb.getPhases
}

// get failsafe timeout from charger
b, err := wb.conn.ReadHoldingRegisters(vestelRegFailsafeTimeout, 1)
if err != nil {
Expand All @@ -111,7 +124,7 @@ func NewVestel(ctx context.Context, uri string, id uint8) (*Vestel, error) {
}
go wb.heartbeat(ctx, timeout)

return wb, nil
return decorateVestel(wb, phasesS, phasesG), err
}

func (wb *Vestel) heartbeat(ctx context.Context, timeout time.Duration) {
Expand Down Expand Up @@ -269,6 +282,21 @@ func (wb *Vestel) Voltages() (float64, float64, float64, error) {
return wb.getPhaseValues(vestelRegVoltages, 1)
}

// phases1p3p implements the api.PhaseSwitcher interface
func (wb *Vestel) phases1p3p(phases int) error {
_, err := wb.conn.WriteSingleRegister(vestelRegNumberPhases, uint16(phases))
return err
}

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

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

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

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

1 change: 1 addition & 0 deletions templates/definition/charger/vestel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ products:
- brand: E.ON Drive
description:
generic: vBox
capabilities: ["1p3p"]
requirements:
evcc: ["sponsorship"]
params:
Expand Down

0 comments on commit 3365c84

Please sign in to comment.