Skip to content

Razer Barracuda Pro: no charging query for a headset that is off, and a refused write is retried (about 4 s less per poll), unit tests - #133

Merged
HeyOkay merged 2 commits into
HeyOkay:mainfrom
ahmedkhursheed23:barracuda-offline-fast
Sep 29, 2026
Merged

HeyOkay merged 2 commits into
HeyOkay:mainfrom
ahmedkhursheed23:barracuda-offline-fast

Conversation

@ahmedkhursheed23

Copy link
Copy Markdown
Contributor

This change removes a long wait from the poll thread. The poll thread reads all providers in sequence, so a slow provider delays the icons of all other devices. The Razer Barracuda Pro provider waited too long when the headset was off. The change does not add or change a command to a device.

1. Problem

  • read_battery sent the charging query also when the battery query got no reply. Each query uses 4 attempts of 6 reads of 150 ms. Thus a headset that is off added approximately 3.6 s to each poll.
  • Session._write did not examine the return value of write(). hidapi returns -1 when a write fails. It does not raise an error. Thus remote() always reported success, and the wake retries did not operate.

Failure scenario: The receiver is plugged in. The headset is off. The poll interval is 15 s. Each poll holds all other icons for approximately 7 s instead of 3.6 s.

2. Change

  • read_battery returns ("offline", None, False) immediately when the battery query gets no reply. It still sends "remote mode off", as before. The offline icon is the same as before.
  • _write returns False when write() returns a negative value. The existing retry logic now operates.

3. Tests

New tests use fake HID devices. They count reads and writes.

  • tests/test_barracuda.py: test_headset_on, test_headset_off_skips_the_charging_query, test_headset_off_costs_one_query_of_reads, test_failed_write_is_retried_for_remote_mode, test_receiver_that_rejects_every_write_sends_no_queries, test_failed_query_write_stops_that_query, test_headset_off_shows_the_offline_icon.

Suite result: all tests pass.

Mutation check: I broke each line of the fix one at a time. At least one new test failed for each mutation.

  • Barracuda: ignore the -1 from write(); remove the early return; remove "remote mode off" on the offline path.

Base and other PRs

read_battery sent the charging query even when the battery query got no
answer, so a switched-off headset cost a second full set of timeouts
(4 x 6 x 150 ms) and held up every other provider on the poll thread.
It now returns the offline result as soon as the battery query is empty
(remote mode is still switched off again, as before).

Session._write ignored write()'s return value; hidapi reports a failed
write by returning -1 rather than raising, so remote() always reported
success and the wake retries never ran. A negative return now counts as
a failure. No frame changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QmGsnjgXs8VbKmmxLkPsf6
@HeyOkay
HeyOkay merged commit 6e4002d into HeyOkay:main Sep 29, 2026
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.

2 participants