summaryrefslogtreecommitdiff
path: root/kvmd/apps
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-22 04:42:22 +0300
committerDevaev Maxim <[email protected]>2020-09-22 04:42:39 +0300
commit55f6956c2bf5057d4069d297ec8887926adacbd8 (patch)
tree8d83089a316a349c267c3c1be6b8a48129879285 /kvmd/apps
parent50c2d9c1c57469946654f09f4fbd6ed82607bd51 (diff)
confirmations for gpio
Diffstat (limited to 'kvmd/apps')
-rw-r--r--kvmd/apps/kvmd/ugpio.py60
1 files changed, 41 insertions, 19 deletions
diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py
index cb328115..d4e9d0af 100644
--- a/kvmd/apps/kvmd/ugpio.py
+++ b/kvmd/apps/kvmd/ugpio.py
@@ -322,29 +322,51 @@ class UserGpio:
items: List[Dict] = []
for item in map(str.strip, row):
if item.startswith("#") or len(item) == 0:
- items.append({
- "type": "label",
- "text": item[1:].strip(),
- })
+ items.append(self.__make_view_label(item))
else:
- parts = list(map(str.strip, item.split("|", 1)))
+ parts = list(map(str.strip, item.split("|", 2)))
if parts:
- channel: str = parts[0]
- param: Optional[str] = (parts[1] if len(parts) > 1 else None)
- if channel in self.__inputs:
- items.append({
- "type": UserGpioModes.INPUT,
- "channel": channel,
- "color": (param if param in ["green", "yellow", "red"] else "green"),
- })
- elif channel in self.__outputs:
- items.append({
- "type": UserGpioModes.OUTPUT,
- "channel": parts[0],
- "text": (param if param is not None else "Click"),
- })
+ if parts[0] in self.__inputs:
+ items.append(self.__make_view_input(parts))
+ elif parts[0] in self.__outputs:
+ items.append(self.__make_view_output(parts))
table.append(items)
+
return {
"header": self.__view["header"],
"table": table,
}
+
+ def __make_view_label(self, item: str) -> Dict:
+ assert item.startswith("#")
+ return {
+ "type": "label",
+ "text": item[1:].strip(),
+ }
+
+ def __make_view_input(self, parts: List[str]) -> Dict:
+ assert len(parts) >= 1
+ color = (parts[1] if len(parts) > 1 else None)
+ if color not in ["green", "yellow", "red"]:
+ color = "green"
+ return {
+ "type": UserGpioModes.INPUT,
+ "channel": parts[0],
+ "color": color,
+ }
+
+ def __make_view_output(self, parts: List[str]) -> Dict:
+ assert len(parts) >= 1
+ confirm = False
+ text = "Click"
+ if len(parts) == 2:
+ text = parts[1]
+ elif len(parts) == 3:
+ confirm = (parts[1] == "confirm")
+ text = parts[2]
+ return {
+ "type": UserGpioModes.OUTPUT,
+ "channel": parts[0],
+ "confirm": confirm,
+ "text": text,
+ }