Skip to content

Commit

Permalink
MMU support is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ondratu committed Feb 7, 2024
1 parent 79bc9f6 commit fc44e3d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
repos:
- repo: https://github.com/pre-commit/mirrors-yapf
rev: 'v0.31.0' # Use the sha / tag you want to point at
rev: 'v0.32.0' # Use the sha / tag you want to point at
hooks:
- id: yapf
additional_dependencies: [toml]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -15,10 +16,10 @@ repos:
# hooks:
# - id: pylint
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.269'
rev: 'v0.2.0'
hooks:
- id: ruff
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
- id: flake8
21 changes: 13 additions & 8 deletions prusa/connect/printer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def __init__(self,
type_: Optional[const.PrinterType] = None,
sn: Optional[str] = None,
fingerprint: Optional[str] = None,
max_retries: int = 1):
max_retries: int = 1,
mmu_supported: bool = True):
self.__type = type_
self.__sn = sn
self.__fingerprint = fingerprint
Expand All @@ -114,6 +115,7 @@ def __init__(self,
self.mbl: Optional[List[float]] = None
self.sheet_settings: Optional[List[Sheet]] = None
self.active_sheet: Optional[int] = None # index
self.mmu_supported: bool = mmu_supported
self.mmu_enabled: bool = False
self.mmu_fw: Optional[str] = None
self.mmu_type: Optional[const.MMUType] = None
Expand Down Expand Up @@ -379,10 +381,6 @@ def get_info(self) -> Dict[str, Any]:
else:
type_, ver, sub = (None, None, None)

mmu: Dict[str, Any] = {"enabled": self.mmu_enabled}
if self.mmu_fw is not None:
mmu["version"] = self.mmu_fw

data = {
"source": const.Source.CONNECT,
"event": const.Event.INFO,
Expand All @@ -400,10 +398,16 @@ def get_info(self) -> Dict[str, Any]:
"mbl": self.mbl,
"sheet_settings": self.sheet_settings,
"active_sheet": self.active_sheet,
"mmu": mmu,
}
if self.mmu_type is not None and self.mmu_enabled:
data["slots"] = MMU_SLOT_COUNTS.get(self.mmu_type)

if self.mmu_supported:
mmu: Dict[str, Any] = {"enabled": self.mmu_enabled}
if self.mmu_fw is not None:
mmu["version"] = self.mmu_fw
data["mmu"] = mmu

if self.mmu_type is not None and self.mmu_enabled:
data["slots"] = MMU_SLOT_COUNTS.get(self.mmu_type)
return data

def send_info(self, caller: Command) -> Dict[str, Any]:
Expand Down Expand Up @@ -602,6 +606,7 @@ def handler(self, command: const.Command):
def gcode(prn, gcode):
...
"""

def wrapper(handler: Callable[[Command], Dict[str, Any]]):
self.set_handler(command, handler)
return handler
Expand Down
44 changes: 44 additions & 0 deletions tests/test_mmu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Tests for MMU support."""
from prusa.connect.printer import Printer, const
from tests.util import FINGERPRINT, SN

# pylint: disable=missing-function-docstring


class TestPrinterMMU:
"""Test mmu support"""

def test_init_supported(self):
printer = Printer(const.PrinterType.I3MK3S, SN, FINGERPRINT)
assert printer.mmu_supported is True

def test_init_unsupported(self):
printer = Printer(const.PrinterType.I3MK3S,
SN,
FINGERPRINT,
mmu_supported=False)
assert printer.mmu_supported is False

def test_get_info_enabled(self):
printer = Printer(const.PrinterType.I3MK3S, SN, FINGERPRINT)
printer.mmu_enabled = True

info = printer.get_info()
assert "mmu" in info
assert info["mmu"]["enabled"] is True

def test_get_info_disabled(self):
printer = Printer(const.PrinterType.I3MK3S, SN, FINGERPRINT)

info = printer.get_info()
assert "mmu" in info
assert info["mmu"]["enabled"] is False

def test_get_info_unsuported_mmu(self):
printer = Printer(const.PrinterType.I3MK3S,
SN,
FINGERPRINT,
mmu_supported=False)

info = printer.get_info()
assert "mmu" not in info

0 comments on commit fc44e3d

Please sign in to comment.