mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 17:20:30 +08:00
improved pins validation
This commit is contained in:
parent
5d1228eb9e
commit
ca812117e4
@ -77,7 +77,7 @@ class _GpioInput:
|
||||
) -> None:
|
||||
|
||||
self.__channel = channel
|
||||
self.__pin: str = config.pin
|
||||
self.__pin: str = str(config.pin)
|
||||
self.__inverted: bool = config.inverted
|
||||
|
||||
self.__driver = driver
|
||||
@ -118,7 +118,7 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes
|
||||
) -> None:
|
||||
|
||||
self.__channel = channel
|
||||
self.__pin: str = config.pin
|
||||
self.__pin: str = str(config.pin)
|
||||
self.__inverted: bool = config.inverted
|
||||
|
||||
self.__switch: bool = config.switch
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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))
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user