Repository navigation
Detect the input characteristic instead of hard-coding it (v1.2.4) - #16
Merged
Merged
Conversation
Fixes #15: a Switch 2 Pro Controller bought in Australia connects fine but has no 7492866c-ec3e-4619-8258-32755ffcc0f9 characteristic, so start_notify raised BleakCharacteristicNotFoundError on every attempt. The input-report UUID is now resolved at connect time: the UUID pinned in mappings.json (ble.input_char) if present, else the documented one, else a probe of the remaining notifiable characteristics — same Nintendo vendor block first, other vendor UUIDs next, SIG-assigned ones last. A candidate is adopted only once it streams reports of at least MIN_REPORT_LEN bytes, so a 1-byte battery-level notification can't be mistaken for input. The winner is persisted, so later connects skip probing. Also: - log the full GATT table on every connect (this is what the issue was missing to be diagnosable) - actionable error when nothing streams: retry moving the sticks, then attach the log - don't call stop_notify for a subscription that never succeeded (it was doubling every failure in the log) - factor the mappings.json write-back into _persist(), shared by the DSU toggle and the new ble.input_char Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Fixes #15.
The bug
The reporter's Switch 2 Pro Controller (bought in Australia) is found and connects, then every attempt dies in
start_notify:That UUID was hard-coded, so any revision that renumbers it was unusable. The log also showed each failure twice, because the teardown called
stop_notifyfor a subscription that had never succeeded.The fix
The input-report characteristic is now resolved at connect time:
mappings.json(ble.input_char), if the device actually exposes it;…f9;A candidate is adopted only after it streams a report of at least
MIN_REPORT_LEN(11) bytes, i.e. something the parser can actually decode — a 1-byte battery-level notification can't win. The adopted UUID is written back tomappings.json, so subsequent connects skip probing entirely.Because some firmwares may only report on change, the menubar notice asks the user to move the sticks while identification runs, and the give-up message says the same before pointing at the log.
Also in here:
GATT: N characteristic(s): …) — this is exactly the information Switch 2 Pro Controller is not recognised #15 was missing to be diagnosable;stop_notifyis only attempted for a subscription that succeeded;mappings.jsonwrite-back is factored into_persist(), shared by the DSU toggle and the newble.input_char.Tests
19 new checks in
tests/test_bridge.pyagainst a fabricated GATT table: known UUID used without probing, pinned UUID honoured, stale pin falling back, renumbered characteristic adopted and persisted, short (battery-like) reports rejected, probe ordering, non-notifiable characteristics skipped, empty GATT, session failing cleanly with no straystop_notify, plusble.input_charparsing and persistence.Both suites pass locally.
Caveat
If that controller exposes no notifiable characteristic streaming ≥ 11-byte reports at all — for instance if its vendor service only appears after an encrypted pairing — the probe will fail too. In that case the new
GATT:log line tells us exactly what the device does expose, which is the follow-up.🤖 Generated with Claude Code