Skip to content

Commit

Permalink
OpenWB 2.0: fix enabled state handling (evcc-io#11543)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusGH committed Jan 7, 2024
1 parent 38cbd3e commit a55ce94
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions charger/openwb-2.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (

// OpenWB20 charger implementation
type OpenWB20 struct {
conn *modbus.Connection
curr uint16
base uint16
conn *modbus.Connection
enabled bool
curr uint16
base uint16
}

const (
Expand Down Expand Up @@ -106,12 +107,7 @@ func (wb *OpenWB20) Status() (api.ChargeStatus, error) {

// Enabled implements the api.Charger interface
func (wb *OpenWB20) Enabled() (bool, error) {
b, err := wb.conn.ReadInputRegisters(wb.base+openwbRegActualAmps, 1)
if err != nil {
return false, err
}

return binary.BigEndian.Uint16(b) == 1, nil
return verifyEnabled(wb, wb.enabled)
}

func (wb *OpenWB20) setCurrent(u uint16) error {
Expand All @@ -125,8 +121,11 @@ func (wb *OpenWB20) Enable(enable bool) error {
if enable {
u = wb.curr
}

return wb.setCurrent(u)
err := wb.setCurrent(u)
if err == nil {
wb.enabled = enable
}
return err
}

// MaxCurrent implements the api.Charger interface
Expand Down

0 comments on commit a55ce94

Please sign in to comment.