From 2d478e45e3dd87907990364682a730fa5763b0c3 Mon Sep 17 00:00:00 2001 From: Ircama Date: Sun, 10 Nov 2024 07:41:42 +0100 Subject: [PATCH] Manage case when stats["snmp_info"]["Power Off Timer"] does not include digits - Solves File "ui.py", line 2541, in detect_configuration IndexError: list index out of range - Removes [INFO] Found data: {}. - improve messages ref #39 --- ui.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/ui.py b/ui.py index 7ca09e1..28e911d 100644 --- a/ui.py +++ b/ui.py @@ -2332,7 +2332,10 @@ def run_detection(): f"[INFO] Models with same access keys: {rwk_kist}\n" ) - if DETECTED in self.printer.PRINTER_CONFIG: + if ( + DETECTED in self.printer.PRINTER_CONFIG + and self.printer.PRINTER_CONFIG[DETECTED] + ): self.status_text.insert( tk.END, f'[INFO] Found data: ' @@ -2371,7 +2374,8 @@ def run_detection(): ) if response: self.status_text.insert( - tk.END, f"[INFO] Starting the operation, please wait...\n" + tk.END, + f"[INFO] Starting the access key detection, please wait for many minutes...\n" ) self.config(cursor="watch") self.update() @@ -2469,7 +2473,7 @@ def detect_sequence(eeprom, sequence): return False self.status_text.insert( tk.END, - f"[INFO] Reading EEPROM values, please wait...\n" + f"[INFO] Reading EEPROM values, please wait for some minutes...\n" ) self.update() try: @@ -2538,14 +2542,18 @@ def detect_sequence(eeprom, sequence): c += 1 if "Power Off Timer" in stats["snmp_info"] and stats["snmp_info"]["Power Off Timer"]: - po_mins = int(re.findall(r'\d+', stats["snmp_info"]["Power Off Timer"])[0]) - msb = po_mins // 256 - lsb = po_mins % 256 - result = detect_sequence(eeprom, (lsb, msb)) - c = 0 - for i in result: - conf_data["po_time[%s]" % c] = [i + 1, i] - c += 1 + matches = re.findall(r'\d+', stats["snmp_info"]["Power Off Timer"]) + if matches: + po_mins = int(matches[0]) + msb = po_mins // 256 + lsb = po_mins % 256 + result = detect_sequence(eeprom, (lsb, msb)) + c = 0 + for i in result: + conf_data["po_time[%s]" % c] = [i + 1, i] + c += 1 + else: + conf_data["po_time"] = None else: conf_data["po_time"] = None