test_nfc_reader.py 1.2 KB

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