Skip to content

Commit

Permalink
solax-charger: fix enable
Browse files Browse the repository at this point in the history
  • Loading branch information
premultiply committed May 14, 2024
1 parent e7db6df commit 142ce36
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions charger/solax.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ const (
solaxRegActivePower = 0x000B // uint16 1W
solaxRegTotalEnergy = 0x0010 // uint32s 0.1kWh
solaxRegState = 0x001D // uint16

solaxCmdStop = 3
solaxCmdStart = 4

solaxModeStop = 0
solaxModeFast = 1
)

func init() {
Expand Down Expand Up @@ -140,18 +146,17 @@ func (wb *Solax) Enabled() (bool, error) {
return false, err
}

return binary.BigEndian.Uint16(b) != 0, nil
return binary.BigEndian.Uint16(b) != solaxModeStop, nil
}

// Enable implements the api.Charger interface
func (wb *Solax) Enable(enable bool) error {
var mode uint16 = 0 // "STOP"
var cmd uint16 = solaxCmdStop
if enable {
mode = 1 // "FAST"
cmd = solaxCmdStart
}

_, err := wb.conn.WriteSingleRegister(solaxRegDeviceMode, mode)

_, err := wb.conn.WriteSingleRegister(solaxRegCommandControl, cmd)
return err
}

Expand Down

0 comments on commit 142ce36

Please sign in to comment.