mirror of
https://github.com/RunLit/Bambu-Run.git
synced 2026-10-21 15:37:38 +01:00
fix(mcp): treat ending_percent=-1 as unread sentinel in normalize_consumed
This commit is contained in:
@@ -108,7 +108,10 @@ def normalize_consumed(starting_percent, ending_percent, initial_weight_grams):
|
|||||||
fabricated zero (spec: 24/269 usage rows go negative; a -1 sentinel
|
fabricated zero (spec: 24/269 usage rows go negative; a -1 sentinel
|
||||||
subtracted as a real value produces e.g. consumed=-101%).
|
subtracted as a real value produces e.g. consumed=-101%).
|
||||||
"""
|
"""
|
||||||
if starting_percent is None or starting_percent == -1 or ending_percent is None:
|
if (
|
||||||
|
starting_percent is None or starting_percent == -1
|
||||||
|
or ending_percent is None or ending_percent == -1
|
||||||
|
):
|
||||||
return None, None, "unreliable"
|
return None, None, "unreliable"
|
||||||
consumed_percent = starting_percent - ending_percent
|
consumed_percent = starting_percent - ending_percent
|
||||||
if consumed_percent < 0:
|
if consumed_percent < 0:
|
||||||
|
|||||||
@@ -109,6 +109,12 @@ def test_normalize_consumed_sentinel_start_goes_unreliable():
|
|||||||
assert normalize_consumed(-1, 100, initial_weight_grams=1000) == (None, None, "unreliable")
|
assert normalize_consumed(-1, 100, initial_weight_grams=1000) == (None, None, "unreliable")
|
||||||
|
|
||||||
|
|
||||||
|
def test_normalize_consumed_sentinel_end_goes_unreliable():
|
||||||
|
# symmetric case: ending_percent == -1 (no RFID reading at job end)
|
||||||
|
# must not fabricate a plausible-looking consumption figure
|
||||||
|
assert normalize_consumed(74, -1, initial_weight_grams=1000) == (None, None, "unreliable")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_resolve_printer_by_id():
|
def test_resolve_printer_by_id():
|
||||||
p = Printer.objects.create(name="RNL-H2C", model="H2C", is_active=True)
|
p = Printer.objects.create(name="RNL-H2C", model="H2C", is_active=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user