Skip to content

fix(dbus): normalize peripheral id at every public entry point#81

Merged
stoprocent merged 2 commits into
mainfrom
fix/dbus-normalize-peripheral-id
May 7, 2026
Merged

fix(dbus): normalize peripheral id at every public entry point#81
stoprocent merged 2 commits into
mainfrom
fix/dbus-normalize-peripheral-id

Conversation

@stoprocent
Copy link
Copy Markdown
Owner

Summary

  • Normalize incoming peripheralUuid to the canonical noble id form (lowercase, no colons) at every public method on the D-Bus bindings
  • Accepts: aabbccddeeff, AABBCCDDEEFF, AaBbCcDdEeFf, AA:BB:CC:DD:EE:FF, aa:bb:cc:dd:ee:ff, Aa:Bb:Cc:Dd:Ee:Ff — all map to aabbccddeeff
  • All emitted events now carry the canonical id regardless of how the caller spelled it
  • null / undefined pass through unchanged so existing "unknown peripheral" no-op paths still work

Why

BlueZ emits MAC addresses uppercase with colons (AA:BB:CC:DD:EE:FF) and uses uppercase underscored form in object paths (/org/bluez/hci0/dev_AA_BB_CC_DD_EE_FF). Internally we already lowercase to build the noble id (aabbccddeeff) and look devices up in a Map keyed by that canonical form. But there was no input normalization — if a user passed an uppercase id or a colon-separated MAC (which is plausible if they have an address hardcoded in config), every internal _devices.get(id) lookup would silently miss and the call would no-op or fall into an error path.

This change makes the binding lenient about input shape and strict about output shape (canonical id everywhere in events).

Methods covered

connect, cancelConnect, disconnect, updateRssi, discoverServices, discoverIncludedServices, discoverCharacteristics, read, write, broadcast, notify, discoverDescriptors, readValue, writeValue, readHandle, writeHandle.

Test plan

  • npx jest — 17 suites, 673 tests pass (+19 new normalization tests, parametrized across 6 input variants for discoverServices / read / readHandle plus a null-safety test)
  • npm run lint — clean
  • Manual verification on Linux: pass an uppercase MAC to peripheral.connect() and confirm BlueZ paths still resolve

🤖 Generated with Claude Code

Marek Serafin and others added 2 commits May 7, 2026 09:34
Replaces undocumented prose-only requirement with a machine-readable
version range so Renovate/Dependabot/`npm ls` can track supported
versions. Marked optional so npm doesn't auto-install on Mac/Win.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
BlueZ emits MAC addresses in uppercase colon form
(AA:BB:CC:DD:EE:FF), while noble's canonical peripheral id is the
colon-stripped lowercase form (aabbccddeeff). External callers may
pass any of: canonical id, uppercase id, mixed-case id, or
uppercase/lowercase/mixed colon-MAC form.

Add a small `normalizeId` helper and apply it at the top of every
public method that accepts a peripheralUuid (connect, disconnect,
cancelConnect, updateRssi, discoverServices,
discoverIncludedServices, discoverCharacteristics, read, write,
broadcast, notify, discoverDescriptors, readValue, writeValue,
readHandle, writeHandle). Internal lookups now match regardless of
the casing/separator the caller used, and emitted events always
carry the canonical id.

Null/undefined ids are passed through unchanged so existing
"unknown peripheral" code paths still kick in instead of throwing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@stoprocent stoprocent merged commit 937bb05 into main May 7, 2026
28 of 29 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

🎉 This PR is included in version 2.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant