Skip to content

Show the battery level of devices behind a receiver in the device picker - #1487

Merged
lujjjh merged 1 commit into
mainfrom
fix-receiver-device-battery-in-picker
Nov 1, 2026
Merged

lujjjh merged 1 commit into
mainfrom
fix-receiver-device-battery-in-picker

Conversation

@lujjjh

@lujjjh lujjjh commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

In the device picker, the devices listed under a Logitech receiver often had no battery level, while the menu bar showed one for the same device.

The picker read ReceiverLogicalDeviceIdentity.batteryLevel, which is only set when receiver discovery manages to read the battery from the device. Discovery cannot read it while the device is idle, and the refresh after a reconnection (validateReceiverSlotIdentity) never reads it. Meanwhile BatteryDeviceMonitor observes each receiver slot over HID++ and already feeds the menu bar.

Change

  • ConnectedBatteryDeviceInfo.batteryLevel(of:inventory:) returns a slot's observed level, falling back to the level from discovery. currentDeviceBatteryLevel now uses it, so its behaviour is unchanged.
  • BatteryDeviceMonitor.batteryLevel(of:) exposes it.
  • DeviceModel publishes pairedReceiverDeviceBatteryLevels by slot, refreshed with the battery monitor and with the receiver's devices, and the picker shows those.

Tests

StatusItemBatteryIndicatorTests gains a case for an identity without a level (as published after a reconnection) taking the slot's observed level, and for no level at all.

xcodebuild test -only-testing:LinearMouseUnitTests: 1182 tests, 0 failures (before #1486 merged; 1187 with it, excluding the window-opening HoverWindowQueryTests).

Verified on hardware

MX Master 3S B on a Logi Bolt receiver, launched while the mouse was idle, so discovery reported battery=(nil). Before the change the picker showed the device under the receiver without a battery level; with it, the level from the slot's observation is shown.

🤖 Generated with Claude Code

@lujjjh lujjjh added the bug Something isn't working label Nov 1, 2026
@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between c03cdbe and e17d5a9.

Files selected for processing: 5
  • LinearMouse/Device/VendorSpecific/BatteryDeviceMonitor.swift
  • LinearMouse/Device/VendorSpecific/ConnectedBatteryDeviceInventory.swift
  • LinearMouse/Model/DeviceModel.swift
  • LinearMouse/UI/Header/DeviceIndicator/DevicePickerSheet/DevicePickerSectionItem.swift
  • LinearMouseUnitTests/UI/StatusItemBatteryIndicatorTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

Walkthrough

Receiver battery levels now use matching inventory observations when available, with a fallback to the receiver identity’s battery level. DeviceModel stores paired receiver levels by slot, and the device picker reads from that map.

Changes: Receiver battery display

Layer / File(s) Summary
Resolve receiver battery levels
LinearMouse/Device/VendorSpecific/BatteryDeviceMonitor.swift, LinearMouse/Device/VendorSpecific/ConnectedBatteryDeviceInventory.swift, LinearMouseUnitTests/UI/StatusItemBatteryIndicatorTests.swift
The lookup checks the matching inventory entry before using the receiver identity’s battery level. The test checks the inventory result and the empty-inventory case.
Publish and display levels
LinearMouse/Model/DeviceModel.swift, LinearMouse/UI/Header/DeviceIndicator/DevicePickerSheet/DevicePickerSectionItem.swift
DeviceModel updates paired receiver battery levels by slot during refresh and clears the map when the device is unavailable. The device picker reads the level for each device’s slot.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to e17d5

Receiver battery levels are ready to merge with no concrete current-head blocker identified.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: displaying battery levels for devices connected through a receiver in the device picker.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description directly explains the missing receiver-device battery levels, the implementation changes, the tests, and the hardware verification. It is related to the changeset.
Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@lujjjh

lujjjh commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lujjjh
lujjjh force-pushed the fix-receiver-device-battery-in-picker branch 2 times, most recently from 9c4154f to 7227f3f Compare November 1, 2026 15:42
Base automatically changed from fix-receiver-slot-name-after-reconnect to main November 1, 2026 15:48
The device picker showed the battery level a device behind a receiver had at
discovery. Discovery cannot read it while the device is idle, and the refresh
after a reconnection never reads it, so the level was often missing although
the battery monitor observes each slot. Prefer the slot's observed level, and
fall back to the one from discovery.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lujjjh
lujjjh force-pushed the fix-receiver-device-battery-in-picker branch from 7227f3f to 59c212d Compare November 1, 2026 15:49
@lujjjh
lujjjh merged commit dd3ec66 into main Nov 1, 2026
2 checks passed
@lujjjh
lujjjh deleted the fix-receiver-device-battery-in-picker branch November 1, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant