summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-07 14:42:29 +0300
committerDevaev Maxim <[email protected]>2020-09-07 14:42:29 +0300
commit1353ca2e974a66e7797dadba0a89fcbe470c7c7c (patch)
tree20182ccf59b6613ba9f2a1cc8921b7f0edf9759a /kvmd
parentc2831853a04168571caa9e639af30a7a0cf6e75d (diff)
optional gpio initial
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py4
-rw-r--r--kvmd/apps/kvmd/ugpio.py13
2 files changed, 9 insertions, 8 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index ce7cfaef..e431dc6e 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -200,8 +200,8 @@ def _patch_dynamic( # pylint: disable=too-many-locals
if mode == "output":
ch_scheme.update({
"busy_delay": Option(0.2, type=valid_float_f01),
- "initial": Option(False, type=valid_bool),
- "switch": Option(True, type=valid_bool),
+ "initial": Option(False, type=(lambda arg: (None if arg is None else valid_bool(arg)))),
+ "switch": Option(True, type=valid_bool),
"pulse": {
"delay": Option(0.1, type=valid_float_f0),
"min_delay": Option(0.1, type=valid_float_f01),
diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py
index b444a48e..f25c511c 100644
--- a/kvmd/apps/kvmd/ugpio.py
+++ b/kvmd/apps/kvmd/ugpio.py
@@ -112,7 +112,7 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes
self.__channel = channel
self.__pin: int = config.pin
self.__inverted: bool = config.inverted
- self.__initial: bool = config.initial
+ self.__initial: Optional[bool] = config.initial
self.__switch: bool = config.switch
@@ -123,7 +123,7 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes
self.__busy_delay: float = config.busy_delay
self.__driver = driver
- self.__driver.register_output(self.__pin, (config.initial ^ config.inverted))
+ self.__driver.register_output(self.__pin, (None if config.initial is None else (config.initial ^ config.inverted)))
self.__region = aiotools.AioExclusiveRegion(GpioChannelIsBusyError, notifier)
@@ -156,10 +156,11 @@ class _GpioOutput: # pylint: disable=too-many-instance-attributes
}
def cleanup(self) -> None:
- try:
- self.__driver.write(self.__pin, (self.__initial ^ self.__inverted))
- except Exception:
- get_logger().exception("Can't cleanup %s", self)
+ if self.__initial is not None:
+ try:
+ self.__driver.write(self.__pin, (self.__initial ^ self.__inverted))
+ except Exception:
+ get_logger().exception("Can't cleanup %s", self)
async def switch(self, state: bool) -> bool:
if not self.__switch: