mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-17 19:36:28 +02:00
Fix P2S showing carbon rod maintenance tasks (#640)
P2S uses hardened steel rods, not carbon fiber. Move P2S from carbon rod classification to new steel_rod category with its own "Lubricate Steel Rods" / "Clean Steel Rods" maintenance tasks.
This commit is contained in:
@@ -34,7 +34,7 @@ router = APIRouter(prefix="/maintenance", tags=["maintenance"])
|
||||
|
||||
# Default maintenance types
|
||||
DEFAULT_MAINTENANCE_TYPES = [
|
||||
# Carbon rod models only (X1/P1/P2S)
|
||||
# Carbon rod models only (X1/P1)
|
||||
{
|
||||
"name": "Lubricate Carbon Rods",
|
||||
"description": "Apply lubricant to carbon rods for smooth motion",
|
||||
@@ -47,6 +47,19 @@ DEFAULT_MAINTENANCE_TYPES = [
|
||||
"default_interval_hours": 100.0,
|
||||
"icon": "Sparkles",
|
||||
},
|
||||
# Steel rod models only (P2S)
|
||||
{
|
||||
"name": "Lubricate Steel Rods",
|
||||
"description": "Apply lubricant to steel rods for smooth motion",
|
||||
"default_interval_hours": 50.0,
|
||||
"icon": "Droplet",
|
||||
},
|
||||
{
|
||||
"name": "Clean Steel Rods",
|
||||
"description": "Wipe steel rods with a dry cloth",
|
||||
"default_interval_hours": 100.0,
|
||||
"icon": "Sparkles",
|
||||
},
|
||||
# Linear rail models only (A1/H2)
|
||||
{
|
||||
"name": "Lubricate Linear Rails",
|
||||
@@ -88,11 +101,13 @@ DEFAULT_MAINTENANCE_TYPES = [
|
||||
]
|
||||
|
||||
# System types that only apply to printers with a specific rod/rail type.
|
||||
# "carbon" = X1/P1/P2S series (carbon rods), "linear_rail" = A1/H2 series.
|
||||
# Types not listed here apply to all printers.
|
||||
# "carbon" = X1/P1 series (carbon rods), "steel_rod" = P2S (steel rods),
|
||||
# "linear_rail" = A1/H2 series. Types not listed here apply to all printers.
|
||||
_ROD_TYPE_REQUIREMENTS: dict[str, str] = {
|
||||
"Lubricate Carbon Rods": "carbon",
|
||||
"Clean Carbon Rods": "carbon",
|
||||
"Lubricate Steel Rods": "steel_rod",
|
||||
"Clean Steel Rods": "steel_rod",
|
||||
"Lubricate Linear Rails": "linear_rail",
|
||||
"Clean Linear Rails": "linear_rail",
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ PRINTER_MODEL_ID_MAP = {
|
||||
|
||||
|
||||
# Rod/rail type classification for maintenance tasks.
|
||||
# Carbon rods: X1, P1, P2S series (CoreXY with carbon fiber rods)
|
||||
# Carbon rods: X1, P1 series (CoreXY with carbon fiber rods)
|
||||
# Steel rods: P2S series (hardened steel linear shafts)
|
||||
# Linear rails: A1, H2 series (linear rail motion system)
|
||||
# Values must be uppercase with spaces stripped for normalized comparison.
|
||||
CARBON_ROD_MODELS = frozenset(
|
||||
@@ -61,11 +62,18 @@ CARBON_ROD_MODELS = frozenset(
|
||||
"X1E",
|
||||
"P1P",
|
||||
"P1S",
|
||||
"P2S",
|
||||
# Internal codes
|
||||
"C11", # X1C
|
||||
"C12", # X1
|
||||
"C13", # X1E
|
||||
]
|
||||
)
|
||||
|
||||
STEEL_ROD_MODELS = frozenset(
|
||||
[
|
||||
# Display names (uppercase, no spaces)
|
||||
"P2S",
|
||||
# Internal codes
|
||||
"N7", # P2S
|
||||
]
|
||||
)
|
||||
@@ -99,7 +107,8 @@ def get_rod_type(model: str | None) -> str | None:
|
||||
"""Return the rod/rail type for a printer model.
|
||||
|
||||
Returns:
|
||||
"carbon" for X1/P1/P2S series (carbon fiber rods),
|
||||
"carbon" for X1/P1 series (carbon fiber rods),
|
||||
"steel_rod" for P2S series (hardened steel rods),
|
||||
"linear_rail" for A1/H2 series (linear rails),
|
||||
None for unknown models.
|
||||
"""
|
||||
@@ -108,6 +117,8 @@ def get_rod_type(model: str | None) -> str | None:
|
||||
normalized = model.strip().upper().replace(" ", "").replace("-", "")
|
||||
if normalized in CARBON_ROD_MODELS:
|
||||
return "carbon"
|
||||
if normalized in STEEL_ROD_MODELS:
|
||||
return "steel_rod"
|
||||
if normalized in LINEAR_RAIL_MODELS:
|
||||
return "linear_rail"
|
||||
return None
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
"""Unit tests for maintenance rod-type filtering logic."""
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.app.api.routes.maintenance import _should_apply_to_printer
|
||||
|
||||
|
||||
class TestShouldApplyToPrinter:
|
||||
"""Tests for _should_apply_to_printer() model-specific filtering."""
|
||||
|
||||
# Carbon rod tasks should only apply to X1/P1 models
|
||||
@pytest.mark.parametrize("model", ["X1C", "X1", "X1E", "P1P", "P1S"])
|
||||
def test_carbon_rod_tasks_apply_to_carbon_models(self, model: str):
|
||||
assert _should_apply_to_printer("Lubricate Carbon Rods", model) is True
|
||||
assert _should_apply_to_printer("Clean Carbon Rods", model) is True
|
||||
|
||||
def test_carbon_rod_tasks_do_not_apply_to_p2s(self):
|
||||
"""P2S has steel rods, not carbon rods (#640)."""
|
||||
assert _should_apply_to_printer("Lubricate Carbon Rods", "P2S") is False
|
||||
assert _should_apply_to_printer("Clean Carbon Rods", "P2S") is False
|
||||
|
||||
def test_carbon_rod_tasks_do_not_apply_to_a1(self):
|
||||
assert _should_apply_to_printer("Lubricate Carbon Rods", "A1") is False
|
||||
|
||||
# Steel rod tasks should only apply to P2S
|
||||
def test_steel_rod_tasks_apply_to_p2s(self):
|
||||
assert _should_apply_to_printer("Lubricate Steel Rods", "P2S") is True
|
||||
assert _should_apply_to_printer("Clean Steel Rods", "P2S") is True
|
||||
|
||||
def test_steel_rod_tasks_do_not_apply_to_x1c(self):
|
||||
assert _should_apply_to_printer("Lubricate Steel Rods", "X1C") is False
|
||||
assert _should_apply_to_printer("Clean Steel Rods", "X1C") is False
|
||||
|
||||
def test_steel_rod_tasks_do_not_apply_to_a1(self):
|
||||
assert _should_apply_to_printer("Lubricate Steel Rods", "A1") is False
|
||||
|
||||
# Linear rail tasks should only apply to A1/H2 models
|
||||
@pytest.mark.parametrize("model", ["A1", "A1 Mini", "H2D", "H2C", "H2S"])
|
||||
def test_linear_rail_tasks_apply_to_rail_models(self, model: str):
|
||||
assert _should_apply_to_printer("Lubricate Linear Rails", model) is True
|
||||
assert _should_apply_to_printer("Clean Linear Rails", model) is True
|
||||
|
||||
def test_linear_rail_tasks_do_not_apply_to_p2s(self):
|
||||
assert _should_apply_to_printer("Lubricate Linear Rails", "P2S") is False
|
||||
|
||||
# Universal tasks apply to all models
|
||||
@pytest.mark.parametrize("model", ["X1C", "P2S", "A1", "H2D"])
|
||||
def test_universal_tasks_apply_to_all(self, model: str):
|
||||
assert _should_apply_to_printer("Clean Nozzle/Hotend", model) is True
|
||||
assert _should_apply_to_printer("Check Belt Tension", model) is True
|
||||
|
||||
# Unknown models default to carbon (legacy behavior)
|
||||
def test_unknown_model_defaults_to_carbon(self):
|
||||
assert _should_apply_to_printer("Lubricate Carbon Rods", "UNKNOWN") is True
|
||||
assert _should_apply_to_printer("Lubricate Steel Rods", "UNKNOWN") is False
|
||||
assert _should_apply_to_printer("Lubricate Linear Rails", "UNKNOWN") is False
|
||||
@@ -0,0 +1,48 @@
|
||||
"""Unit tests for printer model utilities."""
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.app.utils.printer_models import get_rod_type
|
||||
|
||||
|
||||
class TestGetRodType:
|
||||
"""Tests for get_rod_type() rod/rail classification."""
|
||||
|
||||
@pytest.mark.parametrize("model", ["X1C", "X1", "X1E", "P1P", "P1S"])
|
||||
def test_carbon_rod_models(self, model: str):
|
||||
assert get_rod_type(model) == "carbon"
|
||||
|
||||
@pytest.mark.parametrize("model", ["C11", "C12", "C13"])
|
||||
def test_carbon_rod_internal_codes(self, model: str):
|
||||
assert get_rod_type(model) == "carbon"
|
||||
|
||||
def test_p2s_is_steel_rod(self):
|
||||
"""P2S uses hardened steel rods, not carbon rods (#640)."""
|
||||
assert get_rod_type("P2S") == "steel_rod"
|
||||
|
||||
def test_p2s_internal_code_is_steel_rod(self):
|
||||
"""N7 (P2S internal code) uses steel rods."""
|
||||
assert get_rod_type("N7") == "steel_rod"
|
||||
|
||||
@pytest.mark.parametrize("model", ["A1", "A1 Mini", "H2D", "H2D Pro", "H2C", "H2S"])
|
||||
def test_linear_rail_models(self, model: str):
|
||||
assert get_rod_type(model) == "linear_rail"
|
||||
|
||||
@pytest.mark.parametrize("model", ["N1", "N2S", "A11", "A12", "O1D", "O1E", "O2D", "O1C", "O1C2", "O1S"])
|
||||
def test_linear_rail_internal_codes(self, model: str):
|
||||
assert get_rod_type(model) == "linear_rail"
|
||||
|
||||
def test_unknown_model_returns_none(self):
|
||||
assert get_rod_type("UNKNOWN") is None
|
||||
|
||||
def test_none_returns_none(self):
|
||||
assert get_rod_type(None) is None
|
||||
|
||||
def test_case_insensitive(self):
|
||||
assert get_rod_type("p2s") == "steel_rod"
|
||||
assert get_rod_type("x1c") == "carbon"
|
||||
assert get_rod_type("a1") == "linear_rail"
|
||||
|
||||
def test_strips_whitespace_and_dashes(self):
|
||||
assert get_rod_type(" P2S ") == "steel_rod"
|
||||
assert get_rod_type("A1-Mini") == "linear_rail"
|
||||
Reference in New Issue
Block a user