summaryrefslogtreecommitdiff
path: root/kvmd/plugins/ugpio
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2021-09-08 06:08:11 +0300
committerMaxim Devaev <[email protected]>2021-09-08 06:08:11 +0300
commitca812117e48cbc6e2c71947b912748cfd3ff9691 (patch)
treed8daa43c9e606ed0c4226a112e943aa683fd627f /kvmd/plugins/ugpio
parent5d1228eb9e5b159d0909453ed85280b9fb794a9e (diff)
improved pins validation
Diffstat (limited to 'kvmd/plugins/ugpio')
-rw-r--r--kvmd/plugins/ugpio/__init__.py4
-rw-r--r--kvmd/plugins/ugpio/ezcoo.py4
-rw-r--r--kvmd/plugins/ugpio/gpio.py4
-rw-r--r--kvmd/plugins/ugpio/hidrelay.py5
-rw-r--r--kvmd/plugins/ugpio/ipmi.py2
-rw-r--r--kvmd/plugins/ugpio/otgbind.py2
-rw-r--r--kvmd/plugins/ugpio/pwm.py4
-rw-r--r--kvmd/plugins/ugpio/tesmart.py5
-rw-r--r--kvmd/plugins/ugpio/wol.py2
9 files changed, 18 insertions, 14 deletions
diff --git a/kvmd/plugins/ugpio/__init__.py b/kvmd/plugins/ugpio/__init__.py
index f63df5e4..ae9afd53 100644
--- a/kvmd/plugins/ugpio/__init__.py
+++ b/kvmd/plugins/ugpio/__init__.py
@@ -75,7 +75,9 @@ class BaseUserGpioDriver(BasePlugin):
return set(UserGpioModes.ALL)
@classmethod
- def get_pin_validator(cls) -> Callable[[Any], str]:
+ def get_pin_validator(cls) -> Callable[[Any], Any]:
+ # XXX: The returned value will be forcibly converted to a string
+ # in kvmd/apps/kvmd/ugpio.py, i.e. AFTER validation.
raise NotImplementedError
def register_input(self, pin: str, debounce: float) -> None:
diff --git a/kvmd/plugins/ugpio/ezcoo.py b/kvmd/plugins/ugpio/ezcoo.py
index a20aed32..e79ed057 100644
--- a/kvmd/plugins/ugpio/ezcoo.py
+++ b/kvmd/plugins/ugpio/ezcoo.py
@@ -88,8 +88,8 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
}
@classmethod
- def get_pin_validator(cls) -> Callable[[Any], str]:
- return (lambda arg: str(valid_number(arg, min=0, max=3, name="Ezcoo channel")))
+ def get_pin_validator(cls) -> Callable[[Any], Any]:
+ return functools.partial(valid_number, min=0, max=3, name="Ezcoo channel")
def prepare(self) -> None:
assert self.__proc is None
diff --git a/kvmd/plugins/ugpio/gpio.py b/kvmd/plugins/ugpio/gpio.py
index 315de6f1..2064efc5 100644
--- a/kvmd/plugins/ugpio/gpio.py
+++ b/kvmd/plugins/ugpio/gpio.py
@@ -67,8 +67,8 @@ class Plugin(BaseUserGpioDriver):
}
@classmethod
- def get_pin_validator(cls) -> Callable[[Any], str]:
- return (lambda arg: str(valid_gpio_pin(arg)))
+ def get_pin_validator(cls) -> Callable[[Any], Any]:
+ return valid_gpio_pin
def register_input(self, pin: str, debounce: float) -> None:
self.__input_pins[int(pin)] = aiogp.AioReaderPinParams(False, debounce)
diff --git a/kvmd/plugins/ugpio/hidrelay.py b/kvmd/plugins/ugpio/hidrelay.py
index d4bdda48..06bb526d 100644
--- a/kvmd/plugins/ugpio/hidrelay.py
+++ b/kvmd/plugins/ugpio/hidrelay.py
@@ -22,6 +22,7 @@
import asyncio
import contextlib
+import functools
from typing import Dict
from typing import Set
@@ -83,8 +84,8 @@ class Plugin(BaseUserGpioDriver):
return set([UserGpioModes.OUTPUT])
@classmethod
- def get_pin_validator(cls) -> Callable[[Any], str]:
- return (lambda arg: str(valid_number(arg, min=0, max=7, name="HID relay channel")))
+ def get_pin_validator(cls) -> Callable[[Any], Any]:
+ return functools.partial(valid_number, min=0, max=7, name="HID relay channel")
def register_output(self, pin: str, initial: Optional[bool]) -> None:
self.__initials[int(pin)] = initial
diff --git a/kvmd/plugins/ugpio/ipmi.py b/kvmd/plugins/ugpio/ipmi.py
index 718c71cb..f6649d4c 100644
--- a/kvmd/plugins/ugpio/ipmi.py
+++ b/kvmd/plugins/ugpio/ipmi.py
@@ -112,7 +112,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
}
@classmethod
- def get_pin_validator(cls) -> Callable[[Any], str]:
+ def get_pin_validator(cls) -> Callable[[Any], Any]:
actions = ["0", *_OUTPUTS, "status", *_OUTPUTS.values()]
return (lambda arg: check_string_in_list(arg, "IPMI action", actions))
diff --git a/kvmd/plugins/ugpio/otgbind.py b/kvmd/plugins/ugpio/otgbind.py
index 600c8488..ebbcf5fc 100644
--- a/kvmd/plugins/ugpio/otgbind.py
+++ b/kvmd/plugins/ugpio/otgbind.py
@@ -54,7 +54,7 @@ class Plugin(BaseUserGpioDriver):
self.__driver = ""
@classmethod
- def get_pin_validator(cls) -> Callable[[Any], str]:
+ def get_pin_validator(cls) -> Callable[[Any], Any]:
return str
def prepare(self) -> None:
diff --git a/kvmd/plugins/ugpio/pwm.py b/kvmd/plugins/ugpio/pwm.py
index 2bd8807e..642a3f68 100644
--- a/kvmd/plugins/ugpio/pwm.py
+++ b/kvmd/plugins/ugpio/pwm.py
@@ -81,8 +81,8 @@ class Plugin(BaseUserGpioDriver):
return set([UserGpioModes.OUTPUT])
@classmethod
- def get_pin_validator(cls) -> Callable[[Any], str]:
- return (lambda arg: str(valid_gpio_pin(arg)))
+ def get_pin_validator(cls) -> Callable[[Any], Any]:
+ return valid_gpio_pin
def register_output(self, pin: str, initial: Optional[bool]) -> None:
self.__channels[int(pin)] = initial
diff --git a/kvmd/plugins/ugpio/tesmart.py b/kvmd/plugins/ugpio/tesmart.py
index 4bb2351b..ec513cf4 100644
--- a/kvmd/plugins/ugpio/tesmart.py
+++ b/kvmd/plugins/ugpio/tesmart.py
@@ -21,6 +21,7 @@
import asyncio
+import functools
from typing import Tuple
from typing import Dict
@@ -83,8 +84,8 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
}
@classmethod
- def get_pin_validator(cls) -> Callable[[Any], str]:
- return (lambda arg: str(valid_number(arg, min=0, max=15, name="Tesmart channel")))
+ def get_pin_validator(cls) -> Callable[[Any], Any]:
+ return functools.partial(valid_number, min=0, max=15, name="Tesmart channel")
async def run(self) -> None:
prev_active = -2
diff --git a/kvmd/plugins/ugpio/wol.py b/kvmd/plugins/ugpio/wol.py
index 1305b3e6..c3ebda12 100644
--- a/kvmd/plugins/ugpio/wol.py
+++ b/kvmd/plugins/ugpio/wol.py
@@ -69,7 +69,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
}
@classmethod
- def get_pin_validator(cls) -> Callable[[Any], str]:
+ def get_pin_validator(cls) -> Callable[[Any], Any]:
return str
async def read(self, pin: str) -> bool: