ABL: fix detecting enabled state (#1815)

This commit is contained in:
andig 2021-10-31 17:31:16 +01:00 • committed by GitHub
parent 7de872926f
commit 788fc726fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,6 +37,7 @@ type ABLeMH struct {
const (
ablRegFirmware = 0x01
ablRegStatus = 0x04
ablRegEnabled = 0x0F
ablRegAmpsConfig = 0x14
ablRegStatusLong = 0x2E
@ -145,13 +146,13 @@ func (wb *ABLeMH) Status() (api.ChargeStatus, error) {
// Enabled implements the api.Charger interface
func (wb *ABLeMH) Enabled() (bool, error) {
_, _ = wb.conn.ReadHoldingRegisters(ablRegStatusLong, 5)
b, err := wb.conn.ReadHoldingRegisters(ablRegStatusLong, 5)
_, _ = wb.conn.ReadHoldingRegisters(ablRegEnabled, 5)
b, err := wb.conn.ReadHoldingRegisters(ablRegEnabled, 5)
if err != nil {
return false, err
}
u := binary.BigEndian.Uint16(b[2:]) & 0x0FFF
u := binary.BigEndian.Uint16(b[6:]) & 0x0FFF
return u != ablAmpsDisabled, nil
}