diff --git a/kvmd/aiogp.py b/kvmd/aiogp.py index 3ee0ea2b..1b5ca16f 100644 --- a/kvmd/aiogp.py +++ b/kvmd/aiogp.py @@ -23,6 +23,7 @@ import asyncio import threading import dataclasses +import typing import gpiod @@ -101,10 +102,10 @@ class AioReader: # pylint: disable=too-many-instance-attributes if line_req.wait_edge_events(1): new: dict[int, bool] = {} for event in line_req.read_edge_events(): - (pin, value) = self.__parse_event(event) - new[pin] = value - for (pin, value) in new.items(): - self.__values[pin].set(value) + (pin, state) = self.__parse_event(event) + new[pin] = state + for (pin, state) in new.items(): + self.__values[pin].set(state) else: # Timeout # XXX: Лимит был актуален для 1.6. Надо проверить, поменялось ли это в 2.x. # Размер буфера ядра - 16 эвентов на линии. При превышении этого числа, @@ -114,11 +115,12 @@ class AioReader: # pylint: disable=too-many-instance-attributes self.__values[pin].set(bool(value.value)) # type: ignore def __parse_event(self, event: gpiod.EdgeEvent) -> tuple[int, bool]: - if event.event_type == event.Type.RISING_EDGE: - return (event.line_offset, True) - elif event.event_type == event.Type.FALLING_EDGE: - return (event.line_offset, False) - raise RuntimeError(f"Invalid event {event} type: {event.type}") + match event.event_type: + case event.Type.RISING_EDGE: + return (event.line_offset, True) + case event.Type.FALLING_EDGE: + return (event.line_offset, False) + typing.assert_never(event.event_type) class _DebouncedValue: diff --git a/kvmd/plugins/hid/_mcu/gpio.py b/kvmd/plugins/hid/_mcu/gpio.py index ce1d678b..ab401582 100644 --- a/kvmd/plugins/hid/_mcu/gpio.py +++ b/kvmd/plugins/hid/_mcu/gpio.py @@ -68,7 +68,7 @@ class Gpio: # pylint: disable=too-many-instance-attributes self.__line_req = gpiod.request_lines( self.__device_path, consumer="kvmd::hid", - config=config, + config=config, # type: ignore ) def __exit__( diff --git a/kvmd/plugins/hid/spi.py b/kvmd/plugins/hid/spi.py index cf58b5de..6580ba37 100644 --- a/kvmd/plugins/hid/spi.py +++ b/kvmd/plugins/hid/spi.py @@ -153,7 +153,7 @@ class _SpiPhy(BasePhy): # pylint: disable=too-many-instance-attributes ) @contextlib.contextmanager - def __sw_cs_connected(self) -> Generator[(Callable[[bool], bool] | None), None, None]: + def __sw_cs_connected(self) -> Generator[(Callable[[bool], None] | None), None, None]: if self.__sw_cs_pin > 0: with gpiod.request_lines( self.__gpio_device_path, diff --git a/testenv/requirements.txt b/testenv/requirements.txt index 874cc41b..4d6b8a4f 100644 --- a/testenv/requirements.txt +++ b/testenv/requirements.txt @@ -6,3 +6,4 @@ pyrad types-PyYAML types-aiofiles luma.oled +gpiod>=2.3