KlippyRest/Websocket simplify methods into comprehensions
This commit is contained in:
parent
292dda7416
commit
7cd6107998
@ -12,19 +12,14 @@ class KlippyRest:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def endpoint(self):
|
def endpoint(self):
|
||||||
protocol = "http"
|
return f"{'https' if int(self.port) in {443, 7130} else 'http'}://{self.ip}:{self.port}"
|
||||||
if int(self.port) in {443, 7130}:
|
|
||||||
protocol = "https"
|
|
||||||
return f"{protocol}://{self.ip}:{self.port}"
|
|
||||||
|
|
||||||
def get_server_info(self):
|
def get_server_info(self):
|
||||||
return self.send_request("server/info")
|
return self.send_request("server/info")
|
||||||
|
|
||||||
def get_oneshot_token(self):
|
def get_oneshot_token(self):
|
||||||
r = self.send_request("access/oneshot_token")
|
res = self.send_request("access/oneshot_token")
|
||||||
if r is False or 'result' not in r:
|
return res['result'] if 'result' in res else False
|
||||||
return False
|
|
||||||
return r['result']
|
|
||||||
|
|
||||||
def get_printer_info(self):
|
def get_printer_info(self):
|
||||||
return self.send_request("printer/info")
|
return self.send_request("printer/info")
|
||||||
|
@ -38,9 +38,7 @@ class KlippyWebsocket(threading.Thread):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def ws_proto(self):
|
def ws_proto(self):
|
||||||
if int(self.port) in {443, 7130}:
|
return "wss" if int(self.port) in {443, 7130} else "ws"
|
||||||
return "wss"
|
|
||||||
return "ws"
|
|
||||||
|
|
||||||
def retry(self):
|
def retry(self):
|
||||||
self.reconnect_count = 0
|
self.reconnect_count = 0
|
||||||
@ -78,8 +76,7 @@ class KlippyWebsocket(threading.Thread):
|
|||||||
return True
|
return True
|
||||||
token = self._screen.apiclient.get_oneshot_token()
|
token = self._screen.apiclient.get_oneshot_token()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.critical(e, exc_info=True)
|
logging.debug(f"Unable to get oneshot token {e}")
|
||||||
logging.debug("Unable to get oneshot token")
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
self.ws_url = f"{self.ws_proto}://{self._url}/websocket?token={token}"
|
self.ws_url = f"{self.ws_proto}://{self._url}/websocket?token={token}"
|
||||||
@ -92,8 +89,7 @@ class KlippyWebsocket(threading.Thread):
|
|||||||
logging.debug("Starting websocket thread")
|
logging.debug("Starting websocket thread")
|
||||||
self._wst.start()
|
self._wst.start()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.critical(e, exc_info=True)
|
logging.debug(f"Error starting web socket {e}")
|
||||||
logging.debug("Error starting web socket")
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user