mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-31 10:01:53 +08:00
add the ability to use command exit status as a gpio state in ugpio/cmd (#112)
This commit is contained in:
@@ -63,7 +63,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_modes(cls) -> Set[str]:
|
def get_modes(cls) -> Set[str]:
|
||||||
return set([UserGpioModes.OUTPUT])
|
return set([UserGpioModes.OUTPUT, UserGpioModes.INPUT])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_pin_validator(cls) -> Callable[[Any], Any]:
|
def get_pin_validator(cls) -> Callable[[Any], Any]:
|
||||||
@@ -71,6 +71,13 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
|
|
||||||
async def read(self, pin: str) -> bool:
|
async def read(self, pin: str) -> bool:
|
||||||
_ = pin
|
_ = pin
|
||||||
|
try:
|
||||||
|
proc = await aioproc.log_process(self.__cmd, logger=get_logger(0), prefix=str(self))
|
||||||
|
return proc.returncode == 0
|
||||||
|
except Exception as err:
|
||||||
|
get_logger(0).error("Can't run custom command [ %s ]: %s",
|
||||||
|
tools.cmdfmt(self.__cmd), tools.efmt(err))
|
||||||
|
raise GpioDriverOfflineError(self)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def write(self, pin: str, state: bool) -> None:
|
async def write(self, pin: str, state: bool) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user