Repository navigation
React to device changes, and show fully charged and asleep states - #569
casparas123 wants to merge 2 commits into
Conversation
A hidden window receives WM_DEVICECHANGE for USB, HID and Bluetooth radio interfaces and WM_POWERBROADCAST for resume, so a receiver, a cable, a Bluetooth link or a wake-up is polled at once instead of at the next interval. A dock's burst of interfaces is coalesced into one refresh (1.2 s, 3 s after resume); the existing signature check stays as the fallback. DeviceStatus gains full and asleep. A charging reading at 100 % is marked full, which stops the breathing animation and makes the tooltip say "fully charged" in every language; a provider with a real "charged" flag can say so below 100 %. A reading kept for a device the receiver can no longer hear is marked asleep and never keeps a charging flag, so a mouse that slept on the cable does not keep looking like it is charging.
- Listen for the real Bluetooth radio interface
(GUID_BTHPORT_DEVICE_INTERFACE, {0850302A-B344-4FDA-9BE9-90576B8D46F0}).
- Give the event window its own user32/kernel32 prototypes, so 64-bit
handles are passed whole and the shared ctypes.windll is left alone.
Release the window class when the loop ends or no window can be made,
and post WM_QUIT through the same prototypes.
- A kept reading for a sleeping mouse is never charging or fully charged,
and only a live reading at 100 % becomes fully charged. ATK, Attack
Shark R11, Dareu, Finalmouse, HyperX and Lamzu now mark their kept
reading asleep, like Pulsar and Rapoo.
- status.json shows the same charging and full states as the tooltip and
gains `full` and `asleep`.
- Docs and changelog describe what changed. Tests cover each fix and the
fully charged text in every language.
b211f4d to
d46a20a
Compare
|
I went through this PR again and pushed one more commit (
Tests: each fix has a test that fails on the old code, plus one that checks the "fully charged" text in all 11 languages. The full suite passes locally (4306 tests). Still to check on real hardware: the ring at 100 % while charging, plugging a receiver or cable in and out, waking the PC from sleep, and turning Bluetooth off and on. I'm testing these locally now and will report back here. |
|
Tested on Windows with a local build of this branch (
Not tested yet: waking from sleep, because sleep is turned off on this PC. Anyone who can try it: put the PC to sleep, wake it, and check that the levels refresh within a few seconds. |
What
Three related changes around device state:
halo/device_events.py): a hidden top-level window registers for USB device, HID and Bluetooth radio interface notifications, plusWM_POWERBROADCAST. A receiver, a cable, a Bluetooth link or a resume from sleep wakes the poll loop at once instead of at the next interval. A dock's burst of interfaces is coalesced into one refresh (1.2 s after the last message, 3 s after resume). The existing HID signature check stays as the fallback, and the watcher is stopped on exit.DeviceStatus.full: a charging reading at 100 % is marked full, which stops the ring's breathing animation and makes the tooltip say "fully charged" (newstate.fully_chargedkey in all 11 catalogs). A provider with a real "charged" flag can set the same state below 100 %.DeviceStatus.asleep: a reading kept for a device the receiver can no longer hear is asleep, not charging. Pulsar and Rapoo kept such readings with the last charging flag; they now drop the flag, matching the Device Support Request: Rapoo VT9pro #109 lesson that a receiver cannot confirm a charge it cannot hear.Why
Halo notices a plug or unplug by comparing a USB signature every 2.5 s. That costs wake-ups and still misses changes that do not alter the HID tree (a Bluetooth link coming up, the machine resuming). Separately, a charging device at 100 % kept its breathing animation, and a mouse that slept after being on its cable kept a green charging arc.
How tested
fullderivation, the animation gate, the tooltip text in every language and the asleep retained reading (9 tests);WM_DEVICECHANGEandWM_POWERBROADCASTposted to the window both reach the callback, andstop()ends the thread cleanly. A physical plug/unplug test is still pending.Risks
start()returns False and the existing signature check remains the only source — no behaviour change.fullandasleepare appended toDeviceStatus(after the existing fields) so every positional construction keeps its meaning; no provider changes its signature.0x85). That needs its own provider and a claim order so it cannot double-report devices the vendor drivers already read; it belongs in a separate PR.Checklist
pre-release(notmain)CHANGELOG.mdline under[Unreleased]