diff --git a/liquidctl/driver/commander_core.py b/liquidctl/driver/commander_core.py index 932ed645a..2f5626232 100644 --- a/liquidctl/driver/commander_core.py +++ b/liquidctl/driver/commander_core.py @@ -237,6 +237,7 @@ def _send_command(self, command, data=()): def _wake_device_context(self): try: self._send_command(_CMD_WAKE) + self._send_command(_CMD_RESET) yield finally: self._send_command(_CMD_SLEEP) diff --git a/tests/test_commander_core.py b/tests/test_commander_core.py index b8f6795f7..a23d9c611 100644 --- a/tests/test_commander_core.py +++ b/tests/test_commander_core.py @@ -31,7 +31,7 @@ def __init__(self): self._last_write = bytes() self._modes = {} - + self._is_reset = False self._awake = False self.response_prefix = () @@ -52,7 +52,7 @@ def read(self, length): if self._awake: if self._last_write[2] == 0x08: # Get data channel = self._last_write[3] - mode = self._modes[channel] + mode = self._modes.get(channel) if mode[1] == 0x00: if mode[0] == 0x17: # Get speeds data.extend([0x06, 0x00]) @@ -114,16 +114,20 @@ def write(self, data): if data[2] == 0x0d: channel = data[3] - if self._modes[channel] is None: + if (self._is_reset or not self._awake) and self._modes.get(channel) is None: self._modes[channel] = data[4:6] + self._is_reset = False + else: + raise ExpectationNotMet('Previous channel was not reset') elif data[2] == 0x05 and data[3] == 0x01: self._modes[data[4]] = None + self._is_reset = True elif data[2] == 0x01 and data[3] == 0x03 and data[4] == 0x00: self._awake = data[5] == 0x02 elif self._awake: if data[2] == 0x06: # Write command channel = data[3] - mode = self._modes[channel] + mode = self._modes.get(channel) length = u16le_from(data[4:6]) data_type = data[8:10] written_data = data[10:8+length]