klippy: Minor changes to message protocol error

Minor indentation and variable name changes.

Don't remove linebreaks from message_protocol_error lines.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-05-06 21:06:13 -04:00
parent b18786bc91
commit 7e76bd561a
1 changed files with 18 additions and 33 deletions

View File

@ -22,15 +22,13 @@ command to reload the config and restart the host software.
Printer is halted Printer is halted
""" """
message_protocol_error1 = "MCU Protocol error" message_protocol_error1 = """
message_protocol_error2 = """
This is frequently caused by running an older version of the This is frequently caused by running an older version of the
firmware on the MCU(s). Fix by recompiling and flashing the firmware on the MCU(s). Fix by recompiling and flashing the
firmware. firmware.
""" """
message_protocol_error3 = """ message_protocol_error2 = """
Once the underlying issue is corrected, use the "RESTART" Once the underlying issue is corrected, use the "RESTART"
command to reload the config and restart the host software. command to reload the config and restart the host software.
""" """
@ -145,46 +143,33 @@ class Printer:
m.add_printer_objects(config) m.add_printer_objects(config)
# Validate that there are no undefined parameters in the config file # Validate that there are no undefined parameters in the config file
pconfig.check_unused_options(config) pconfig.check_unused_options(config)
def _build_protocol_error_message(self, e): def _build_protocol_error_message(self, e):
host_version = self.start_args['software_version'] host_version = self.start_args['software_version']
msg_update = [] msg_update = []
msg_updated = [] msg_updated = []
for mcu_name, mcu in self.lookup_objects('mcu'):
for n,mcu_obj in self.lookup_objects('mcu'):
try: try:
mcu_version = mcu_obj.get_status()['mcu_version'] mcu_version = mcu.get_status()['mcu_version']
except: except:
logging.exception("Unable to retrieve mcu_version from mcu_obj") logging.exception("Unable to retrieve mcu_version from mcu")
continue continue
if mcu_version != host_version: if mcu_version != host_version:
msg_update.append("%s: Current version %s" % ( msg_update.append("%s: Current version %s"
n.split()[-1], mcu_obj.get_status()['mcu_version'])) % (mcu_name.split()[-1], mcu_version))
else: else:
msg_updated.append("%s: Current version %s" % ( msg_updated.append("%s: Current version %s"
n.split()[-1], mcu_obj.get_status()['mcu_version'])) % (mcu_name.split()[-1], mcu_version))
if not msg_update:
if len(msg_updated) == 0: msg_update.append("<none>")
if not msg_updated:
msg_updated.append("<none>") msg_updated.append("<none>")
msg = ["MCU Protocol error",
version_msg = ["\nYour Klipper version is: %s\n" % host_version, message_protocol_error1,
"MCU(s) which should be updated:", "Your Klipper version is: %s" % (host_version,),
"\n%s\n" % "\n".join(msg_update), "MCU(s) which should be updated:"]
"Up-to-date MCU(s):", msg += msg_update + ["Up-to-date MCU(s):"] + msg_updated
"\n%s\n" % "\n".join(msg_updated)] msg += [message_protocol_error2, str(e)]
msg = [message_protocol_error1,
"",
' '.join(message_protocol_error2.splitlines())[1:],
"\n".join(version_msg),
' '.join(message_protocol_error3.splitlines())[1:],
"",
str(e)]
return "\n".join(msg) return "\n".join(msg)
def _connect(self, eventtime): def _connect(self, eventtime):
try: try:
self._read_config() self._read_config()