Files
bambuddy/spoolbuddy/tests/test_nfc_reader.py
T
maziggyandKeybored02 12e543b1b4 Fix SpoolBuddy reading the filament type as the Bambu spool ID (#984)
The daemon took tray_uuid from tag blocks 4-5, which hold the filament
type, so every spool of one type sent the same value and the kiosk never
saved it. Read block 9, which both tags of a spool share and the AMS
reports as tray_uuid. Save it on kiosk quick-add and link in local and
Spoolman mode, and give spools added before the fix their tray_uuid when
their exact tag UID is scanned again. Drop any tray_uuid that is not a v4
UUID, so daemons that are not updated yet keep matching by tag UID.

Block 9 read based on #1200 by @Keybored02.

Co-Authored-By: Keybored02 <Keybored02@users.noreply.github.com>
2026-10-03 12:19:04 +02:00

29 lines
1.2 KiB
Python

"""Tests for daemon.nfc_reader — tray UUID extraction from Bambu tag blocks."""
from daemon.nfc_reader import _extract_tray_uuid
# Measured on a real spool: block 9 equals the tray_uuid the AMS reports (#984).
BLOCK9 = bytes.fromhex("9E0B0717BEE94D7887EB1D8DFD1A14F3")
# Block 4 of a "PLA Matte" spool -- what the old blocks 4+5 read sent as tray_uuid.
BLOCK4_PLA_MATTE = b"PLA Matte" + b"\x00" * 7
class TestExtractTrayUuid:
def test_reads_block_9(self):
blocks = {1: b"\x01" * 16, 2: b"\x02" * 16, 4: BLOCK4_PLA_MATTE, 5: b"\x00" * 16, 9: BLOCK9}
assert _extract_tray_uuid(blocks) == "9E0B0717BEE94D7887EB1D8DFD1A14F3"
def test_ignores_blocks_4_and_5(self):
"""Without block 9 there is no tray UUID, never the filament type from block 4."""
blocks = {4: BLOCK4_PLA_MATTE, 5: b"\x00" * 16}
assert _extract_tray_uuid(blocks) is None
def test_all_zero_block_9_is_no_uuid(self):
assert _extract_tray_uuid({9: b"\x00" * 16}) is None
def test_short_block_9_is_no_uuid(self):
assert _extract_tray_uuid({9: b"\x9e\x0b"}) is None
def test_empty_blocks(self):
assert _extract_tray_uuid({}) is None