-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connect option for loading all error codes (#134)
* connect option for loading all error codes * add MK39 option which copies the MK4 codes
- Loading branch information
Showing
9 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ __pycache__ | |
.coverage | ||
*.egg-info | ||
build | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
include prusaerrors/sl1/errors.yaml | ||
include prusaerrors/mmu/errors.yaml | ||
include prusaerrors/buddy/errors.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../yaml/buddy-error-codes.yaml |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# This file is part of the SL1 firmware | ||
# Copyright (C) 2020 Prusa Research a.s. - www.prusa3d.com | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
""" | ||
All printer type error/attention codes | ||
Warning: The codes might not have yet been officially approved. | ||
""" | ||
import re | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
import yaml | ||
|
||
from prusaerrors.shared.codes import unique_codes, Codes, Printer, Code, Category | ||
|
||
|
||
BUDDY = ['MINI', 'MK4', 'IX', 'XL', 'MK35', 'MK39'] | ||
|
||
|
||
class PrinterCode(Code): | ||
""" | ||
Code class holds error code information | ||
""" | ||
|
||
@property | ||
def code(self) -> str: | ||
""" | ||
Get error code | ||
:return: Error code | ||
""" | ||
return f"x{self.raw_code}" | ||
|
||
|
||
def yaml_codes(src_path: Path): | ||
""" | ||
Add code definitions from YAML source | ||
""" | ||
|
||
def decor(cls): | ||
with src_path.open("r") as src_file: | ||
data = yaml.safe_load(src_file) | ||
assert "Errors" in data | ||
|
||
code_re = re.compile( | ||
r"^(?P<printer>([0-9][0-9]|XX))" | ||
r"(?P<category>[0-9])" | ||
r"(?P<error>[0-9][0-9])$") | ||
for entry in data["Errors"]: | ||
code_parts = code_re.match(entry["code"]).groupdict() | ||
category = Category(int(code_parts["category"])) | ||
error = int(code_parts["error"]) | ||
|
||
# code is common for printers defined in printers attribute | ||
if code_parts["printer"] == 'XX': | ||
if printers := entry.get("printers"): | ||
if 'MK4' in printers: | ||
printers.append('MK39') | ||
else: # if no printers specified code is valid for all buddy | ||
printers = BUDDY | ||
|
||
for printer in printers: | ||
printer = Printer[printer.upper().replace(".", "")] | ||
code = PrinterCode( | ||
printer, category, error, entry["title"], | ||
entry["text"], entry.get("approved", False)) | ||
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)) | ||
setattr(cls, str(code), code) | ||
return cls | ||
|
||
return decor | ||
|
||
|
||
@unique_codes | ||
@yaml_codes(Path(__file__).parent.parent / "sl1" / "errors.yaml") | ||
@yaml_codes(Path(__file__).parent.parent / "mmu" / "errors.yaml") | ||
@yaml_codes(Path(__file__).parent.parent / "buddy" / "errors.yaml") | ||
class PrinterCodes(Codes): | ||
""" | ||
Load all the printer type error, exception and warning identification codes | ||
Content is loaded by yaml_codes decorators. | ||
""" | ||
|
||
@classmethod | ||
def get(cls, code: str) -> Optional[Code]: | ||
""" | ||
Get Code by its number | ||
:param code: Code number as string | ||
:return: Code instance | ||
""" | ||
try: | ||
return super().get(f"x{code}") | ||
except KeyError: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../yaml/mmu-error-codes.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This file is part of the SL1 firmware | ||
# Copyright (C) 2020 Prusa Research a.s. - www.prusa3d.com | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
# pylint: disable = missing-function-docstring | ||
# pylint: disable = missing-class-docstring | ||
# pylint: disable = missing-module-docstring | ||
|
||
import unittest | ||
|
||
from prusaerrors.shared.codes import Printer, Category | ||
from prusaerrors.connect.codes import PrinterCodes | ||
|
||
|
||
class TestErrors(unittest.TestCase): | ||
|
||
def test_code_lookup(self): | ||
code = PrinterCodes.get("17505") | ||
assert code.printer == Printer(17) | ||
assert code.category == Category(5) | ||
assert code.error == 5 | ||
assert code.title | ||
assert code.message | ||
|
||
def test_unknown_code(self): | ||
code = PrinterCodes.get("unknown_code") | ||
assert code is None | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |