summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-11-11 12:56:34 +0300
committerDevaev Maxim <[email protected]>2020-11-11 22:24:25 +0300
commitfef625aee52015dfdca0a96c31eced033663cb97 (patch)
tree6538d8ccbff354a94ac765e2df759bcdd596893b
parenta8a075c203e2a458ff51ce0d4152ab09a4710d65 (diff)
refactoring
-rw-r--r--kvmd/plugins/hid/serial.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py
index 9bfafc69..dee992b6 100644
--- a/kvmd/plugins/hid/serial.py
+++ b/kvmd/plugins/hid/serial.py
@@ -47,6 +47,7 @@ class _SerialPhyConnection(BasePhyConnection):
def send(self, request: bytes) -> bytes:
assert len(request) == 8
+ assert request[0] == 0x33
if self.__tty.in_waiting:
self.__tty.read_all()
assert self.__tty.write(request) == 8
@@ -76,24 +77,21 @@ class _SerialPhy(BasePhy):
# =====
class Plugin(BaseMcuHid):
- def __init__(
- self,
- device_path: str,
- speed: int,
- read_timeout: float,
- **kwargs: Any,
- ) -> None:
-
- super().__init__(
- phy=_SerialPhy(device_path, speed, read_timeout),
- **kwargs,
- )
+ def __init__(self, **kwargs: Any) -> None:
+ phy_kwargs: Dict = {key: kwargs.pop(key) for key in self.__get_phy_options()}
+ super().__init__(phy=_SerialPhy(**phy_kwargs), **kwargs)
@classmethod
def get_plugin_options(cls) -> Dict:
return {
+ **cls.__get_phy_options(),
+ **BaseMcuHid.get_plugin_options(),
+ }
+
+ @classmethod
+ def __get_phy_options(cls) -> Dict:
+ return {
"device": Option("", type=valid_abs_path, unpack_as="device_path"),
"speed": Option(115200, type=valid_tty_speed),
"read_timeout": Option(2.0, type=valid_float_f01),
- **BaseMcuHid.get_plugin_options(),
}