43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
"""Matter onboarding payload, checked against the real sticker of the bench box
|
|
(QR decoded from matter_commissioning_qr.png: MT:Y.K9042C00KA0648G00)."""
|
|
|
|
from pathlib import Path
|
|
|
|
import segno
|
|
|
|
from kota_tech.core.logfile import read_log_file
|
|
from kota_tech.matter.payload import SetupPayload, payload_from_log, verhoeff_check
|
|
|
|
STICKER_QR = "MT:Y.K9042C00KA0648G00"
|
|
STICKER_MANUAL = "34970112332" # printed as 3497-011-2332
|
|
|
|
|
|
def test_default_payload_matches_sticker():
|
|
p = SetupPayload()
|
|
assert p.qr_text() == STICKER_QR
|
|
assert p.manual_code() == STICKER_MANUAL
|
|
assert p.manual_code_pretty() == "3497-011-2332"
|
|
|
|
|
|
def test_payload_from_real_boot_log():
|
|
lines = [ln.text for ln in read_log_file(Path(__file__).parent / "fixtures" / "serial_log_20260917_162548.txt")]
|
|
p = payload_from_log(lines)
|
|
assert p.from_log and (p.vendor_id, p.product_id, p.discriminator) == (0xFFF1, 0x8000, 3840)
|
|
assert p.qr_text() == STICKER_QR
|
|
|
|
|
|
def test_other_discriminator_changes_both_codes():
|
|
p = SetupPayload(discriminator=1234)
|
|
assert p.qr_text() != STICKER_QR and p.manual_code() != STICKER_MANUAL
|
|
assert p.qr_text().startswith("MT:") and len(p.qr_text()) == 3 + 19
|
|
|
|
|
|
def test_verhoeff():
|
|
assert verhoeff_check("3497011233") == 2
|
|
assert verhoeff_check("236") == 3 # textbook example
|
|
|
|
|
|
def test_qr_renders():
|
|
qr = segno.make(STICKER_QR, error="m")
|
|
assert qr.symbol_size(border=0)[0] >= 21
|