From 6ba19ea9dde3acb7ad291275c53fadcbc4f035b2 Mon Sep 17 00:00:00 2001 From: "sarka.faloutova" Date: Tue, 12 Mar 2024 13:32:59 +0100 Subject: [PATCH] connect: load error id from yaml --- prusaerrors/connect/codes.py | 23 ++++++++++++++++++++--- prusaerrors/shared/codes.py | 6 +++--- tests/test_connect.py | 1 + 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/prusaerrors/connect/codes.py b/prusaerrors/connect/codes.py index 2a2b5f0..afeaed5 100644 --- a/prusaerrors/connect/codes.py +++ b/prusaerrors/connect/codes.py @@ -25,6 +25,21 @@ class PrinterCode(Code): """ + # pylint: disable = too-many-arguments + def __init__( + self, + printer: Printer, + category: Category, + error: int, + title: str, + message: str, + approved: bool, + id_: str, + ): + super().__init__(printer=printer, category=category, error=error, + title=title, message=message, approved=approved) + self.id = id_ + @property def code(self) -> str: """ @@ -66,14 +81,16 @@ def decor(cls): printer = Printer[printer.upper().replace(".", "")] code = PrinterCode( printer, category, error, entry["title"], - entry["text"], entry.get("approved", False)) + entry["text"], entry.get("approved", False), + entry["id"]) setattr(cls, str(code), code) # code contains printer number else: printer = Printer(int(code_parts["printer"])) code = PrinterCode(printer, category, error, entry["title"], - entry["text"], entry.get("approved", False)) + entry["text"], entry.get("approved", False), + entry["id"]) setattr(cls, str(code), code) return cls @@ -92,7 +109,7 @@ class PrinterCodes(Codes): """ @classmethod - def get(cls, code: str) -> Optional[Code]: + def get(cls, code: str) -> Optional[PrinterCode]: """ Get Code by its number diff --git a/prusaerrors/shared/codes.py b/prusaerrors/shared/codes.py index bb4d09c..550bbf1 100644 --- a/prusaerrors/shared/codes.py +++ b/prusaerrors/shared/codes.py @@ -11,7 +11,7 @@ import re from enum import unique, IntEnum from pathlib import Path -from typing import Optional, TextIO, Dict +from typing import TextIO, Dict import yaml @@ -65,8 +65,8 @@ def __init__( printer: Printer, category: Category, error: int, - title: Optional[str], - message: Optional[str], + title: str, + message: str, approved: bool, ): if printer.value < 0 or printer.value > 99: diff --git a/tests/test_connect.py b/tests/test_connect.py index 5b65aa0..5cc8284 100644 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -21,6 +21,7 @@ def test_code_lookup(self): assert code.error == 5 assert code.title assert code.message + assert code.id def test_unknown_code(self): code = PrinterCodes.get("unknown_code")