summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-08-08 00:57:17 +0300
committerMaxim Devaev <[email protected]>2022-08-08 00:57:17 +0300
commitde6fd9434993b87ff6e5569c3984f76b5ad963a9 (patch)
tree761b3ecd50936adb355e8b9863d778ef17f48b73
parent2482b466a3e45be1e02e1243892c0162d42998bf (diff)
refactoring
-rw-r--r--kvmd/apps/kvmd/api/atx.py4
-rw-r--r--kvmd/apps/kvmd/api/hid.py2
-rw-r--r--kvmd/apps/kvmd/api/log.py7
-rw-r--r--kvmd/apps/kvmd/api/msd.py2
-rw-r--r--kvmd/apps/kvmd/api/streamer.py24
-rw-r--r--kvmd/apps/kvmd/api/ugpio.py6
-rw-r--r--kvmd/apps/kvmd/server.py2
7 files changed, 22 insertions, 25 deletions
diff --git a/kvmd/apps/kvmd/api/atx.py b/kvmd/apps/kvmd/api/atx.py
index 68ce0479..80342daa 100644
--- a/kvmd/apps/kvmd/api/atx.py
+++ b/kvmd/apps/kvmd/api/atx.py
@@ -47,7 +47,7 @@ class AtxApi:
@exposed_http("POST", "/atx/power")
async def __power_handler(self, request: Request) -> Response:
action = valid_atx_power_action(request.query.get("action"))
- wait = valid_bool(request.query.get("wait", "0"))
+ wait = valid_bool(request.query.get("wait", False))
await ({
"on": self.__atx.power_on,
"off": self.__atx.power_off,
@@ -59,7 +59,7 @@ class AtxApi:
@exposed_http("POST", "/atx/click")
async def __click_handler(self, request: Request) -> Response:
button = valid_atx_button(request.query.get("button"))
- wait = valid_bool(request.query.get("wait", "0"))
+ wait = valid_bool(request.query.get("wait", False))
await ({
"power": self.__atx.click_power,
"power_long": self.__atx.click_power_long,
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py
index a683921c..93658e88 100644
--- a/kvmd/apps/kvmd/api/hid.py
+++ b/kvmd/apps/kvmd/api/hid.py
@@ -132,7 +132,7 @@ class HidApi:
@exposed_http("POST", "/hid/print")
async def __print_handler(self, request: Request) -> Response:
text = await request.text()
- limit = int(valid_int_f0(request.query.get("limit", "1024")))
+ limit = int(valid_int_f0(request.query.get("limit", 1024)))
if limit > 0:
text = text[:limit]
symmap = self.__ensure_symmap(request.query.get("keymap", self.__default_keymap_name))
diff --git a/kvmd/apps/kvmd/api/log.py b/kvmd/apps/kvmd/api/log.py
index dd95aa4f..af80bee9 100644
--- a/kvmd/apps/kvmd/api/log.py
+++ b/kvmd/apps/kvmd/api/log.py
@@ -41,16 +41,13 @@ class LogApi:
@exposed_http("GET", "/log")
async def __log_handler(self, request: Request) -> StreamResponse:
- seek = valid_log_seek(request.query.get("seek", "0"))
- follow = valid_bool(request.query.get("follow", "false"))
-
+ seek = valid_log_seek(request.query.get("seek", 0))
+ follow = valid_bool(request.query.get("follow", False))
response = await start_streaming(request, "text/plain")
-
async for record in self.__log_reader.poll_log(seek, follow):
await response.write(("[%s %s] --- %s" % (
record["dt"].strftime("%Y-%m-%d %H:%M:%S"),
record["service"],
record["msg"],
)).encode("utf-8") + b"\r\n")
-
return response
diff --git a/kvmd/apps/kvmd/api/msd.py b/kvmd/apps/kvmd/api/msd.py
index bea4eac2..74290d89 100644
--- a/kvmd/apps/kvmd/api/msd.py
+++ b/kvmd/apps/kvmd/api/msd.py
@@ -138,7 +138,7 @@ class MsdApi:
@exposed_http("POST", "/msd/write_remote")
async def __write_remote_handler(self, request: Request) -> Union[Response, StreamResponse]: # pylint: disable=too-many-locals
url = valid_url(request.query.get("url"))
- insecure = valid_bool(request.query.get("insecure", "0"))
+ insecure = valid_bool(request.query.get("insecure", False))
timeout = valid_float_f01(request.query.get("timeout", 10.0))
remove_incomplete = self.__get_remove_incomplete(request)
diff --git a/kvmd/apps/kvmd/api/streamer.py b/kvmd/apps/kvmd/api/streamer.py
index 0cadb141..401795ce 100644
--- a/kvmd/apps/kvmd/api/streamer.py
+++ b/kvmd/apps/kvmd/api/streamer.py
@@ -57,12 +57,12 @@ class StreamerApi:
@exposed_http("GET", "/streamer/snapshot")
async def __take_snapshot_handler(self, request: Request) -> Response:
snapshot = await self.__streamer.take_snapshot(
- save=valid_bool(request.query.get("save", "false")),
- load=valid_bool(request.query.get("load", "false")),
- allow_offline=valid_bool(request.query.get("allow_offline", "false")),
+ save=valid_bool(request.query.get("save", False)),
+ load=valid_bool(request.query.get("load", False)),
+ allow_offline=valid_bool(request.query.get("allow_offline", False)),
)
if snapshot:
- if valid_bool(request.query.get("ocr", "false")):
+ if valid_bool(request.query.get("ocr", False)):
langs = self.__ocr.get_available_langs()
return Response(
body=(await self.__ocr.recognize(
@@ -72,19 +72,19 @@ class StreamerApi:
subval=(lambda lang: check_string_in_list(lang, "OCR lang", langs)),
name="OCR langs list",
),
- left=int(valid_number(request.query.get("ocr_left", "-1"))),
- top=int(valid_number(request.query.get("ocr_top", "-1"))),
- right=int(valid_number(request.query.get("ocr_right", "-1"))),
- bottom=int(valid_number(request.query.get("ocr_bottom", "-1"))),
+ left=int(valid_number(request.query.get("ocr_left", -1))),
+ top=int(valid_number(request.query.get("ocr_top", -1))),
+ right=int(valid_number(request.query.get("ocr_right", -1))),
+ bottom=int(valid_number(request.query.get("ocr_bottom", -1))),
)),
headers=dict(snapshot.headers),
content_type="text/plain",
)
- elif valid_bool(request.query.get("preview", "false")):
+ elif valid_bool(request.query.get("preview", False)):
data = await snapshot.make_preview(
- max_width=valid_int_f0(request.query.get("preview_max_width", "0")),
- max_height=valid_int_f0(request.query.get("preview_max_height", "0")),
- quality=valid_stream_quality(request.query.get("preview_quality", "80")),
+ max_width=valid_int_f0(request.query.get("preview_max_width", 0)),
+ max_height=valid_int_f0(request.query.get("preview_max_height", 0)),
+ quality=valid_stream_quality(request.query.get("preview_quality", 80)),
)
else:
data = snapshot.data
diff --git a/kvmd/apps/kvmd/api/ugpio.py b/kvmd/apps/kvmd/api/ugpio.py
index b41fba73..cfc08e21 100644
--- a/kvmd/apps/kvmd/api/ugpio.py
+++ b/kvmd/apps/kvmd/api/ugpio.py
@@ -51,14 +51,14 @@ class UserGpioApi:
async def __switch_handler(self, request: Request) -> Response:
channel = valid_ugpio_channel(request.query.get("channel"))
state = valid_bool(request.query.get("state"))
- wait = valid_bool(request.query.get("wait", "0"))
+ wait = valid_bool(request.query.get("wait", False))
await self.__user_gpio.switch(channel, state, wait)
return make_json_response()
@exposed_http("POST", "/gpio/pulse")
async def __pulse_handler(self, request: Request) -> Response:
channel = valid_ugpio_channel(request.query.get("channel"))
- delay = valid_float_f0(request.query.get("delay", "0"))
- wait = valid_bool(request.query.get("wait", "0"))
+ delay = valid_float_f0(request.query.get("delay", 0.0))
+ wait = valid_bool(request.query.get("wait", False))
await self.__user_gpio.pulse(channel, delay, wait)
return make_json_response()
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 6cb2ef5e..84724407 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -226,7 +226,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
@exposed_http("GET", "/ws")
async def __ws_handler(self, request: Request) -> WebSocketResponse:
- stream = valid_bool(request.query.get("stream", "true"))
+ stream = valid_bool(request.query.get("stream", True))
async with self._ws_session(request, stream=stream) as ws:
stage1 = [
("gpio_model_state", self.__user_gpio.get_model()),