fix: handle manufacturer ID 0 in newest_manufacturer_data#219
Merged
Conversation
… ID 0 Manufacturer ID 0 (Ericsson Technology Licensing) is a valid Bluetooth SIG identifier but the current truthiness check on the dict key drops the result. Test fails against current code, will pass after fix.
The previous implementation used a walrus expression that treated the dict key as a truthiness check (\`if manufacturer_data and (last_id := ...)\`), which silently returned None when the most recent manufacturer ID was 0 (Ericsson Technology Licensing) — a valid Bluetooth SIG identifier. Replace with an explicit emptiness check plus next(reversed(...)) which also avoids materializing the keys into a list.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #219 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 248 248
Branches 37 37
=========================================
Hits 248 248 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes newest_manufacturer_data incorrectly returning None when the newest (most recently inserted) manufacturer ID is 0 by removing a falsy-key check and selecting the newest key via reverse-iteration.
Changes:
- Replace the truthiness-based walrus condition with an explicit empty-dict guard.
- Use
next(reversed(manufacturer_data))to select the newest inserted manufacturer ID without allocating a list. - Add a regression test covering manufacturer ID
0for single- and multi-entry dicts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/bluetooth_data_tools/utils.py |
Fixes newest-key selection logic so manufacturer ID 0 is handled correctly and efficiently. |
tests/test_utils.py |
Adds regression coverage ensuring manufacturer ID 0 is not dropped. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bdraco
approved these changes
May 15, 2026
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
Fix
newest_manufacturer_datasilently returningNonewhen the most recently inserted manufacturer ID is0.Why
Manufacturer ID
0is assigned by the Bluetooth SIG to Ericsson Technology Licensing — a valid identifier that real devices may emit. The previous implementation usedif manufacturer_data and (last_id := list(manufacturer_data)[-1]), which treats the key itself as a truthiness check. Withlast_id == 0, the walrus condition is falsy and the function returnsNone, dropping otherwise-valid advertisement data.How
next(reversed(manufacturer_data))instead oflist(...)[-1]— same insertion-order semantics, no list allocation.Testing
test_newest_manufacturer_data_id_zerocovering the single-entry and multi-entry cases. Test commit (909e934) precedes the fix commit (3991f6e) so reviewers can verify the failing-then-passing transition.64 passed.🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 10 insertions(+), 3 deletions(-)
Code scan: clean
Tests: failed ([Errno 13] Permission denied: 'pytest')
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline