Improve error messages (#549)

Shows if the issue is with moonraker or klipper
if the issue is with klipper and there is info about it then show it
Reconnect now has a counter and it's visible to the user
This commit is contained in:
Alfredo Monclus
2022-03-18 20:18:53 -03:00
committed by GitHub
parent 7dc74f74f4
commit 046e03b883
4 changed files with 49 additions and 24 deletions

View File

@@ -31,6 +31,7 @@ class KlippyWebsocket(threading.Thread):
connected = False
callback_table = {}
reconnect_timeout = None
reconnect_count = 0
def __init__(self, screen, callback, host, port):
threading.Thread.__init__(self)
@@ -49,6 +50,8 @@ class KlippyWebsocket(threading.Thread):
self.connect()
def connect(self):
_ = self._screen.lang.gettext
def ws_on_close(ws, a=None, b=None):
self.on_close(ws)
@@ -63,7 +66,18 @@ class KlippyWebsocket(threading.Thread):
try:
state = self._screen.apiclient.get_server_info()
if state is False or state['result']['klippy_connected'] is False:
if state is False:
if self.reconnect_count > 3:
self._screen.printer_initializing(_("Cannot connect to Moonraker") +
("\n\n%s\n\n") % self._url +
_("Retry #%s") % self.reconnect_count)
return False
if state['result']['klippy_connected'] is False:
if self.reconnect_count > 3:
self._screen.printer_initializing(_("Moonraker: connected") +
("\n\nKlipper: %s\n\n") % state['result']['klippy_state'] +
_("Retry #%s") % self.reconnect_count)
return False
printer_info = self._screen.apiclient.get_printer_info()
if printer_info is False:
@@ -137,6 +151,7 @@ class KlippyWebsocket(threading.Thread):
logging.info("Moonraker Websocket Open")
logging.info("Self.connected = %s" % self.is_connected())
self.connected = True
self.reconnect_count = 0
if self.reconnect_timeout is not None:
GLib.source_remove(self.reconnect_timeout)
self.reconnect_timeout = None
@@ -180,6 +195,7 @@ class KlippyWebsocket(threading.Thread):
return False
logging.debug("Attempting to reconnect")
self.reconnect_count += 1
self.connect()
return True