Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delta AC MAX Basic: fix status #15963

Merged
merged 3 commits into from
Sep 8, 2024
Merged
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
34 changes: 33 additions & 1 deletion charger/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Delta struct {
curr float64
base uint16
enabled bool
isBasic bool
}

const (
Expand Down Expand Up @@ -101,6 +102,11 @@ func NewDelta(uri, device, comset string, baudrate int, proto modbus.Protocol, s

wb.base = connector * 1000

// check for basic or smart register set
if _, err := wb.conn.ReadInputRegisters(wb.base+deltaRegEvseChargerState, 1); err != nil {
wb.isBasic = true
}

b, err := wb.conn.ReadHoldingRegisters(deltaRegCommunicationTimeoutEnabled, 1)
if err != nil {
return nil, fmt.Errorf("failsafe timeout enabled: %w", err)
Expand Down Expand Up @@ -153,7 +159,12 @@ func (wb *Delta) Status() (api.ChargeStatus, error) {
switch s := encoding.Uint16(b); s {
case 0, 1, 2:
return api.StatusA, nil
case 3, 5, 6, 7, 9:
case 3:
if wb.isBasic {
return api.StatusA, nil
}
return api.StatusB, nil
case 5, 6, 7, 9:
return api.StatusB, nil
case 4:
return api.StatusC, nil
Expand All @@ -162,6 +173,27 @@ func (wb *Delta) Status() (api.ChargeStatus, error) {
}
}

var _ api.StatusReasoner = (*Delta)(nil)

// statusReason implements the api.StatusReasoner interface
premultiply marked this conversation as resolved.
Show resolved Hide resolved
func (wb *Delta) StatusReason() (api.Reason, error) {
if !wb.isBasic {
b, err := wb.conn.ReadInputRegisters(wb.base+deltaRegEvseState, 1)
if err != nil {
return api.ReasonUnknown, err
}

switch s := encoding.Uint16(b); s {
case 3:
return api.ReasonWaitingForAuthorization, nil
case 5:
return api.ReasonDisconnectRequired, nil
}
}

return api.ReasonUnknown, nil
}

// Enabled implements the api.Charger interface
func (wb *Delta) Enabled() (bool, error) {
b, err := wb.conn.ReadHoldingRegisters(wb.base+deltaRegEvseChargingPowerLimit, 2)
Expand Down