Skip to content

Commit

Permalink
connect: load error id from yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkafa authored and filipkotoucek committed Mar 12, 2024
1 parent 9d2e3bd commit 6ba19ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
23 changes: 20 additions & 3 deletions prusaerrors/connect/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions prusaerrors/shared/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 6ba19ea

Please sign in to comment.