Skip to content

Commit

Permalink
fix toggle on all relays
Browse files Browse the repository at this point in the history
  • Loading branch information
lyimmi committed Sep 1, 2023
1 parent e68bdcc commit 13405c2
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,29 @@ func (d *Device) Toggle(ch RelayNumber) error {
return ErrDeviceNotConnected
}

s := d.state[ch]
if ch == R_ALL {
for i := 1; i <= int(d.relayCount); i++ {
r := RelayNumber(i)
s := switchState(d.state[r])
if err := d.changeState(s, r); err != nil {
return err
}
}
return nil
}

s := switchState(d.state[ch])
return d.changeState(s, ch)
}

func switchState(s State) State {
switch s {
case ON:
s = OFF
break
return OFF
case OFF:
s = ON
break
return ON
}

return d.changeState(s, ch)
return OFF
}

// On sets one or all of the relays state on the device to ON
Expand Down

0 comments on commit 13405c2

Please sign in to comment.