From 68bae20e69eb556bd85c353c5558d63f441f037b Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 9 Nov 2023 20:56:33 -0500 Subject: [PATCH] revert kevin mcu protocol message change (#92) * revert kevin mcu protocol message change * small code quality fixes --- klippy/klippy.py | 49 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/klippy/klippy.py b/klippy/klippy.py index 2405a5381..f28453772 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -22,6 +22,8 @@ Printer is halted """ +message_protocol_error = """MCU Protocol error""" + message_protocol_error1 = """ This is frequently caused by running an older version of the firmware on the MCU(s). Fix by recompiling and flashing the @@ -204,36 +206,55 @@ def _read_config(self): def _build_protocol_error_message(self, e): host_version = self.start_args["software_version"] + msg_update = [] msg_updated = [] - for mcu_name, _mcu in self.lookup_objects("mcu"): + + for mcu_name, mcu_obj in self.lookup_objects("mcu"): try: - mcu_version = _mcu.get_status()["mcu_version"] + mcu_version = mcu_obj.get_status()["mcu_version"] except: - logging.exception("Unable to retrieve mcu_version from mcu") + logging.exception("Unable to retrieve mcu_version from mcu_obj") continue + if mcu_version != host_version: msg_update.append( "%s: Current version %s" - % (mcu_name.split()[-1], mcu_version) + % ( + mcu_name.split()[-1], + mcu_obj.get_status()["mcu_version"], + ) ) else: msg_updated.append( "%s: Current version %s" - % (mcu_name.split()[-1], mcu_version) + % ( + mcu_name.split()[-1], + mcu_obj.get_status()["mcu_version"], + ) ) - if not msg_update: - msg_update.append("") - if not msg_updated: + + if not len(msg_updated): msg_updated.append("") - msg = [ - "MCU Protocol error", - message_protocol_error1, - "Your Klipper version is: %s" % (host_version,), + + version_msg = [ + "\nYour Klipper version is: %s\n" % host_version, "MCU(s) which should be updated:", + "\n%s\n" % "\n".join(msg_update), + "Up-to-date MCU(s):", + "\n%s\n" % "\n".join(msg_updated), ] - msg += msg_update + ["Up-to-date MCU(s):"] + msg_updated - msg += [message_protocol_error2, str(e)] + + msg = [ + message_protocol_error, + "", + " ".join(message_protocol_error1.splitlines())[1:], + "\n".join(version_msg), + " ".join(message_protocol_error2.splitlines())[1:], + "", + str(e), + ] + return "\n".join(msg) def _connect(self, eventtime):