xk-hk4401: fixed regexp

This commit is contained in:
Maxim Devaev
2021-10-03 01:48:39 +03:00
parent d0c237c177
commit 1c3155daec

View File

@@ -169,15 +169,13 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
channel: Optional[int] = None channel: Optional[int] = None
if tty.in_waiting: if tty.in_waiting:
data += tty.read_all() data += tty.read_all()
found = re.findall(b"AG0[0-4]gA", data) found = re.findall(b"AG0[1-4]gA", data)
data = data[-12:]
if found: if found:
try: try:
channel = int(found[-1][2:4]) - 1 channel = int(found[-1][2:4]) - 1
except Exception: except Exception:
return (None, data) channel = None
assert 0 <= channel <= 3 data = data[-12:]
return (channel, data) return (channel, data)
def __send_channel(self, tty: serial.Serial, channel: int) -> None: def __send_channel(self, tty: serial.Serial, channel: int) -> None: