Skip to content

fix: handle manufacturer ID 0 in newest_manufacturer_data#219

Merged
bdraco merged 2 commits into
mainfrom
koan/fix-newest-manufacturer-data-id-zero
May 15, 2026
Merged

fix: handle manufacturer ID 0 in newest_manufacturer_data#219
bdraco merged 2 commits into
mainfrom
koan/fix-newest-manufacturer-data-id-zero

Conversation

@bluetoothbot
Copy link
Copy Markdown
Contributor

@bluetoothbot bluetoothbot commented May 14, 2026

What

Fix newest_manufacturer_data silently returning None when the most recently inserted manufacturer ID is 0.

Why

Manufacturer ID 0 is assigned by the Bluetooth SIG to Ericsson Technology Licensing — a valid identifier that real devices may emit. The previous implementation used if manufacturer_data and (last_id := list(manufacturer_data)[-1]), which treats the key itself as a truthiness check. With last_id == 0, the walrus condition is falsy and the function returns None, dropping otherwise-valid advertisement data.

How

  • Replace the walrus check with an explicit emptiness check on the dict.
  • Use next(reversed(manufacturer_data)) instead of list(...)[-1] — same insertion-order semantics, no list allocation.

Testing

  • Added test_newest_manufacturer_data_id_zero covering the single-entry and multi-entry cases. Test commit (909e934) precedes the fix commit (3991f6e) so reviewers can verify the failing-then-passing transition.
  • Full suite: 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

… 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
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c8bb40b) to head (3991f6e).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 14, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing koan/fix-newest-manufacturer-data-id-zero (3991f6e) with main (c8bb40b)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (493115d) during the generation of this report, so c8bb40b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 0 for 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 bdraco marked this pull request as ready for review May 15, 2026 07:07
@bdraco bdraco merged commit 8fca6ff into main May 15, 2026
52 checks passed
@bdraco bdraco deleted the koan/fix-newest-manufacturer-data-id-zero branch May 15, 2026 07:07
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.

3 participants