always reinit printer on state changes

This commit is contained in:
alfrix 2022-11-16 16:07:48 -03:00
parent b68cfa40fd
commit 18d8f835a9
3 changed files with 6 additions and 11 deletions

View File

@ -260,7 +260,7 @@ class MoonrakerApi:
) )
def object_subscription(self, updates): def object_subscription(self, updates):
logging.debug(f"Sending printer.objects.subscribe: {updates}") logging.debug("Sending printer.objects.subscribe")
return self._ws.send_method( return self._ws.send_method(
"printer.objects.subscribe", "printer.objects.subscribe",
updates updates

View File

@ -51,7 +51,6 @@ class Printer:
self.output_pin_count = None self.output_pin_count = None
def reinit(self, printer_info, data): def reinit(self, printer_info, data):
logging.debug(f"Moonraker object status: {data}")
self.config = data['configfile']['config'] self.config = data['configfile']['config']
self.extrudercount = 0 self.extrudercount = 0
self.tempdevcount = 0 self.tempdevcount = 0
@ -164,6 +163,7 @@ class Printer:
def change_state(self, state): def change_state(self, state):
if state not in list(self.state_callbacks): # disconnected, startup, ready, shutdown, error, paused, printing if state not in list(self.state_callbacks): # disconnected, startup, ready, shutdown, error, paused, printing
return return
if state != self.state:
logging.debug(f"Changing state from '{self.state}' to '{state}'") logging.debug(f"Changing state from '{self.state}' to '{state}'")
self.state = state self.state = state
if self.state_callbacks[state] is not None: if self.state_callbacks[state] is not None:

View File

@ -704,14 +704,15 @@ class KlipperScreen(Gtk.Window):
if self.is_updating(): if self.is_updating():
self.update_queue.append([callback]) self.update_queue.append([callback])
else: else:
self.init_printer()
callback() callback()
def state_disconnected(self, msg=None): def state_disconnected(self, msg=None):
logging.debug("### Going to disconnected") logging.debug("### Going to disconnected")
self.printer.state = "disconnected"
self.close_screensaver() self.close_screensaver()
msg = _("Klipper has disconnected") if msg is None else msg msg = _("Klipper has disconnected") if msg is None else msg
self.printer_initializing(msg) self.printer_initializing(msg)
self.init_printer()
def state_error(self): def state_error(self):
self.close_screensaver() self.close_screensaver()
@ -742,7 +743,6 @@ class KlipperScreen(Gtk.Window):
# Do not return to main menu if completing a job, timeouts/user input will return # Do not return to main menu if completing a job, timeouts/user input will return
if "job_status" in self._cur_panels: if "job_status" in self._cur_panels:
return return
self.init_printer()
self.printer_ready() self.printer_ready()
def state_startup(self): def state_startup(self):
@ -915,11 +915,6 @@ class KlipperScreen(Gtk.Window):
self.printer_initializing("Unable to get printer info from moonraker") self.printer_initializing("Unable to get printer info from moonraker")
return False return False
data = self.apiclient.send_request("printer/objects/query?" + "&".join(PRINTER_BASE_STATUS_OBJECTS))
if data is False:
self.printer_initializing("Error getting printer object data")
return False
config = self.apiclient.send_request("printer/objects/query?configfile") config = self.apiclient.send_request("printer/objects/query?configfile")
if config is False: if config is False:
self.printer_initializing("Error getting printer configuration") self.printer_initializing("Error getting printer configuration")