fix(cli): diag selects a device that exposes the feature under test#150
fix(cli): diag selects a device that exposes the feature under test#150recchia wants to merge 2 commits into
Conversation
Replaces the single-device picker with one that enumerates all online devices and selects by optional --device name filter or required HID++ feature presence, avoiding wrong-device errors when a mouse and keyboard are both paired over Bluetooth-direct. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR replaces the single-call
Confidence Score: 5/5Safe to merge — the new device-selection logic handles all three tiers (explicit query, feature probe, first-online fallback) correctly, probe errors are now logged rather than silently swallowed, and the changes are additive to the CLI surface. The refactor is well-scoped: No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["select_device(query, required_features)"] --> B["online_devices()"]
B --> C{query set?}
C -- yes --> D["Find first device whose name contains query (case-insensitive)"]
D -- found --> E["Return (route, name)"]
D -- not found --> F["no_match_err: list online devices + suggest --device"]
C -- no --> G{required_features non-empty?}
G -- yes --> H["For each device: dump_features(route)"]
H -- "Ok(entries): any feature matches" --> E
H -- "Ok(entries): no match" --> I["Try next device"]
H -- "Err(e)" --> J["tracing::warn! + try next device"]
I --> K{More devices?}
J --> K
K -- yes --> H
K -- no / G=no --> L["devices.into_iter().next()"]
L -- Some --> E
L -- None --> M["no_match_err: no online device found"]
Reviews (2): Last reviewed commit: "fix(cli): address greptile review on sel..." | Re-trigger Greptile |
- Log a tracing::warn when dump_features fails so silent fallthrough to the wrong device is visible in the output. - Add --device <NAME> to `diag lighting` for parity with dpi/smartshift; features is intentionally left without it (it already dumps all devices). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Closes #148 (Finding 2). Builds on the verification in #148.
first_online_device()returned the first online paired device regardless ofkind. With a keyboard + mouse paired over Bluetooth-direct (each enumerates as
its own inventory), a mouse-only diag picks the keyboard and fails:
This replaces it with
select_device(query, required_features):diag dpi/diag smartshiftnow prefer an online device whose HID++ featuretable advertises the feature under test (
0x2201, and0x2110/0x2111),so a paired keyboard is skipped automatically.
--device <name>override (case-insensitive substring match).Non-breaking: existing invocations work unchanged;
diag featuresanddiag lightingare untouched. Verified on Ubuntu 26.04 / Wayland — with bothdevices online,
diag dpinow targets the MX Master 3S without powering off thekeyboard, and
--device masterselects it explicitly.