Skip to content

feat: add NFC tag write support (command 0x0083)#137

Merged
g4bri3lDev merged 4 commits into
mainfrom
feat/nfc-write
Jul 16, 2026
Merged

feat: add NFC tag write support (command 0x0083)#137
g4bri3lDev merged 4 commits into
mainfrom
feat/nfc-write

Conversation

@g4bri3lDev

Copy link
Copy Markdown
Member

Adds host-side support for the firmware NFC endpoint (command 0x0083, moved from 0x0082 which collided with PIPE_WRITE_END).

Layers

  • Protocol: CommandCode.NFC_ENDPOINT, NfcRecordType enum (TEXT/URI/WELL_KNOWN_RAW/MIME/RAW_NDEF), builders for inline write and chunked write (start/data/end), constants (inline threshold 120, chunk size 120, max total 512 matching the firmware staging buffer).
  • Responses: validate_nfc_response distinguishing write OK (0x81) from chunk ACK (0x82) and decoding the {0xFF,0x83,0xFF,err} error frame into NfcWriteError (with error_code). NfcNotSupportedError covers silence from pre-0x83 firmware, which does not NACK unknown opcodes.
  • Device API: write_nfc(rec_type, payload) with automatic inline/chunked selection, plus write_nfc_url, write_nfc_text, and write_nfc_mime (vCards etc., payload [mime_len][mime_type][body]).

Verification

  • 830 unit tests green, including byte-exact frame assertions, chunked-path sequences, error mapping, and the encrypted response delivery path.
  • Hardware verified against a Solum tag on firmware v2.2+7efd063: inline URL write over an encrypted session, chunked 165-byte vCard (read back via NFC Tools), client-side oversize rejection. Negative test on v2.0 firmware correctly raises NfcNotSupportedError.

Consumed by the Home Assistant integration's upcoming write_nfc action.

Adds validate_nfc_response() for the NFC_ENDPOINT (0x0083) response
frames, distinguishing the write-OK (0x81) and chunk-ACK (0x82)
statuses that the generic validate_ack_response() cannot tell apart,
and decoding the firmware's dedicated {0xFF, 0x83, 0xFF, err} error
frame via NfcWriteError. NfcNotSupportedError covers the separate
case of no response at all, which pre-0x83 firmware produces for any
unknown opcode and so cannot be treated as a confirmed rejection.
Adds the public async NFC write API (write_nfc, write_nfc_url,
write_nfc_text, write_nfc_mime) on OpenDisplayDevice, tying together the
NFC_ENDPOINT command builders and response validation from the prior two
tasks. Inline payloads use a single write; larger payloads chunk through
start/data/end frames. A read timeout on the first response of a write
maps to NfcNotSupportedError (silent pre-0x83 firmware); later timeouts
propagate.
@g4bri3lDev
g4bri3lDev merged commit d7f49c0 into main Jul 16, 2026
5 checks passed
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant