Files
bambuddy/backend/tests/unit/test_chamber_temp_ceiling.py
maziggy b04664c64a Raise the chamber-temperature ceiling from 60 to 65 C
Every field that takes a chamber target stopped at 60: the per-filament
chamber map and per-print override in Preheat & Heat Soak, the chamber
quick-select presets, and the printer-card chamber control. 60 is the
X1E's ceiling and the X1E was the only heated-chamber model when that
limit was written; the H2 series and X2D heat to 65, so the top of their
range was unreachable.

The ceiling now lives in one constant per side (MAX_CHAMBER_TEMP_C in
backend/app/utils/printer_models.py and frontend/src/utils/printer.ts)
rather than as a literal at each call site. X1E firmware clamps a higher
request to its own maximum, so a shared ceiling is safe.

Also fixes a live bug at PrintersPage.tsx:7985: parsePresetTriple was
bounded to 60 there, and it rejects the whole triple on any out-of-range
entry, so a saved 65 preset would have silently reverted the printer
card to the defaults while Settings still showed 65.
2026-08-03 08:52:23 +02:00

67 lines
2.6 KiB
Python

"""The chamber-temperature ceiling is shared by every surface that accepts one.
Reported on Discord: the preheat & heat-soak inputs capped at 60 °C, which put
the top of the H2 series' range (65 °C) out of reach. The ceiling now lives in
one place — ``MAX_CHAMBER_TEMP_C`` — and these tests pin both its value and the
fact that each schema actually derives its bound from it rather than carrying a
private literal that could drift back to 60.
"""
import pytest
from pydantic import ValidationError
from backend.app.schemas.print_queue import (
PrintQueueBulkUpdate,
PrintQueueItemCreate,
PrintQueueItemUpdate,
)
from backend.app.schemas.settings import AppSettingsUpdate
from backend.app.utils.printer_models import MAX_CHAMBER_TEMP_C
# The H2 series (H2C / H2D / H2D Pro / H2S) and X2D heat the chamber to 65 °C.
# X1E stops at 60 and clamps in firmware. Hard-coded here on purpose: if the
# constant moves, that should be a deliberate edit, not a silent one.
EXPECTED_CEILING = 65
# (schema, kwargs the schema requires beyond the field under test)
OVERRIDE_SCHEMAS = [
(PrintQueueItemCreate, {}),
(PrintQueueItemUpdate, {}),
(PrintQueueBulkUpdate, {"item_ids": [1]}),
]
def test_ceiling_is_65():
assert MAX_CHAMBER_TEMP_C == EXPECTED_CEILING
@pytest.mark.parametrize("schema,required", OVERRIDE_SCHEMAS)
def test_override_accepts_the_ceiling(schema, required):
model = schema(preheat_chamber_target_override=MAX_CHAMBER_TEMP_C, **required)
assert model.preheat_chamber_target_override == MAX_CHAMBER_TEMP_C
@pytest.mark.parametrize("schema,required", OVERRIDE_SCHEMAS)
def test_override_rejects_above_the_ceiling(schema, required):
with pytest.raises(ValidationError):
schema(preheat_chamber_target_override=MAX_CHAMBER_TEMP_C + 1, **required)
@pytest.mark.parametrize("schema,required", OVERRIDE_SCHEMAS)
def test_override_still_accepts_zero(schema, required):
"""0 is "no chamber phase, even if the filament map wants one" — raising
the ceiling must not disturb the low end."""
model = schema(preheat_chamber_target_override=0, **required)
assert model.preheat_chamber_target_override == 0
def test_chamber_presets_accept_the_ceiling():
payload = f"[35, 45, {MAX_CHAMBER_TEMP_C}]"
assert AppSettingsUpdate(chamber_temp_presets=payload).chamber_temp_presets == payload
def test_chamber_presets_reject_above_the_ceiling():
with pytest.raises(ValidationError) as exc:
AppSettingsUpdate(chamber_temp_presets=f"[35, 45, {MAX_CHAMBER_TEMP_C + 1}]")
assert f"[0, {MAX_CHAMBER_TEMP_C}]" in str(exc.value)