Repository navigation
feat(client): add get_cards() - #96
Open
dariusz-rudzinski wants to merge 1 commit into
Open
dariusz-rudzinski wants to merge 1 commit into
dariusz-rudzinski wants to merge 1 commit into
Conversation
Lists enrolled IC cards via CMD 0x05 sub-op IC_SEARCH (0x01), mirroring get_fingerprints(). Adds CardEntry, the `ttlock get-cards` CLI command and README entries. The 4-byte card id path, multi-card listing, the zero-card case and the end-of-list response are hardware-verified, and the command is confirmed admin-gated; only the 8-byte card id path is not. Cannot detect cyclic restrictions (CMD 0x70 is not implemented for any credential type). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
dariusz-rudzinski
force-pushed
the
feat/get-cards
branch
from
October 3, 2026 18:55
bdc6435 to
d11c078
Compare
Contributor
Author
|
Squashed the branch into a single commit (d11c078) after opening the PR. The tree is identical to what was there before, so there is no content change. Updated the description to move the zero-card case and the admin-handshake requirement to "verified" (both confirmed on hardware since the first draft). |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
TTLockClient.get_cards()lists the IC cards (tags) enrolled on a lock, mirroringget_fingerprints(): admin-gated, one indexed BLE query per card over a single connection and handshake, stopping at the lock's own end-of-list response, with a safety cap that raises instead of returning a possibly incomplete list.CardEntrymodel (card_id,start_date,end_date, plusis_permanent/has_explicit_start), exported from the top-level packagettlock get-cards <lock>CLI commandProtocol
CMD 0x05(COMM_IC_MANAGE), sub-op0x01(IC_SEARCH):[0x01] + index(2 bytes, big-endian), starting at 0[battery][op_echo][position:2][card_id][start:5][end:5][battery][0x01][0xFF][0xFF], as a SUCCESS response, the same shape as fingerprintsDifferences from fingerprints:
CardEntryhas noslot. The byte math leaves no room for one: 18 = 1 + 1 + 2 + 4 + 5 + 5.card_idlength is variable. The official SDK reads 8 bytes when its own buffer is exactly 20 bytes ([position:2][entries...], which excludes battery and op_echo) and 4 otherwise. In this library's framing that is 22 vs 18 bytes, not the SDK's literal 20. There is a regression test that a 20-bytedataraises.positionis discarded, as it is for fingerprints. The client uses its own incrementing index.Verified vs. not verified
Verified on real hardware (an SN484_PV53 lock), via
ttlock get-cards:card_idpathNot verified:
card_idpath (22-byte entries). It is derived from the SDK only and is marked as such in the docstrings and in its test, because no available card produces it.Known limitation
Like
get_fingerprints(), this cannot detect cyclic (day-of-week/time-range) restrictions. That data lives in a separate mechanism (CMD 0x70) that this library doesn't implement for any credential type yet. A card listed as permanent or timed may still be limited to specific days/hours. This is stated in theCardEntryandget_cards()docstrings, in the CLI output, and in the README.Tests
ruff, mypy and pytest pass (479 tests, 99.24% coverage). Fixtures mirror the real captures, with synthetic card ids substituted for the real ones, since a card UID can be a cloneable credential.
Follow-up
Once this is released, I'd like to add a card hub with per-card child devices to
ha-ttlock-ble, following the fingerprint pattern. That depends on attlock-blerelease containingget_cards().