diff options
Diffstat (limited to 'kvmd/plugins/ugpio')
-rw-r--r-- | kvmd/plugins/ugpio/__init__.py | 13 | ||||
-rw-r--r-- | kvmd/plugins/ugpio/hidrelay.py | 10 |
2 files changed, 21 insertions, 2 deletions
diff --git a/kvmd/plugins/ugpio/__init__.py b/kvmd/plugins/ugpio/__init__.py index 1e7725e8..9ed48a5f 100644 --- a/kvmd/plugins/ugpio/__init__.py +++ b/kvmd/plugins/ugpio/__init__.py @@ -20,6 +20,7 @@ # ========================================================================== # +from typing import Set from typing import Type from typing import Optional from typing import Any @@ -47,6 +48,14 @@ class GpioDriverOfflineError(GpioOperationError): # ===== +class UserGpioModes: + INPUT = "input" + OUTPUT = "output" + + ALL = set([INPUT, OUTPUT]) + + +# ===== class BaseUserGpioDriver(BasePlugin): def __init__( # pylint: disable=super-init-not-called self, @@ -61,6 +70,10 @@ class BaseUserGpioDriver(BasePlugin): def get_instance_id(self) -> str: return self._instance_name + @classmethod + def get_modes(cls) -> Set[str]: + return set(UserGpioModes.ALL) + def register_input(self, pin: int) -> None: raise NotImplementedError diff --git a/kvmd/plugins/ugpio/hidrelay.py b/kvmd/plugins/ugpio/hidrelay.py index 85d2f808..b7f88cb8 100644 --- a/kvmd/plugins/ugpio/hidrelay.py +++ b/kvmd/plugins/ugpio/hidrelay.py @@ -24,6 +24,7 @@ import asyncio import contextlib from typing import Dict +from typing import Set from typing import Optional import hid @@ -39,6 +40,7 @@ from ...validators.basic import valid_float_f01 from ...validators.os import valid_abs_path from . import GpioDriverOfflineError +from . import UserGpioModes from . import BaseUserGpioDriver @@ -73,8 +75,12 @@ class Plugin(BaseUserGpioDriver): "state_poll": Option(5.0, type=valid_float_f01), } + @classmethod + def get_modes(cls) -> Set[str]: + return set([UserGpioModes.OUTPUT]) + def register_input(self, pin: int) -> None: - _ = pin + raise RuntimeError(f"Unsupported mode 'input' for pin={pin} on {self}") def register_output(self, pin: int, initial: Optional[bool]) -> None: self.__initials[pin] = initial @@ -153,7 +159,7 @@ class Plugin(BaseUserGpioDriver): def __check_pin(self, pin: int) -> bool: ok = (0 <= pin <= 7) if not ok: - get_logger(0).warning("Unsupported pin for %s on %s: %d", self, self.__device_path, pin) + get_logger(0).warning("Unsupported pin=%d for %s on %s", pin, self, self.__device_path) return ok @contextlib.contextmanager |