Repository navigation
fix(battery): consider every line power device, not just the first - #187
Merged
Merged
Conversation
`watch_battery_plug_events` took the first upower device whose name starts with `line_power` and watched only that one. Where a stale ACPI AC device is enumerated ahead of the supplies that actually work, the daemon reads its `Online` forever and never sees a plug event. On a ThinkPad T490 running Pop!_OS 24.04, upower enumerates `line_power_AC`, `line_power_ucsi_source_psy_USBC000o001` and `line_power_ucsi_source_psy_USBC000o002`. With the charger connected, `/sys/class/power_supply/AC/online` reads 1 and the first `ucsi` device reports `Online = true`, while `line_power_AC` stays `false` and never emits a change. `line_power_AC` is enumerated first, so `is_on_battery` is stuck at `true` and no plug event ever arrives. The critical battery alert therefore cannot be stopped by plugging in; it ends only once charging carries the level back over 10%. Collect every `line_power` device instead, treat the machine as on mains power when any of them is online, and recompute across all of them whenever one changes. The 500ms debounce and the semantics of the returned watch function are unchanged. Measured on that machine by logging the daemon's own `pw-play` invocations while unplugging and replugging. Unpatched, neither `power-unplug` nor `power-plug` was played. Patched, both were played in the same second as the sysfs transition. `line_power_AC.Online` remained `false` throughout, so the change works around the stale device rather than depending on it. Drafted with AI assistance (Claude Code). I understand the change, built it and measured it on real hardware as described. Closes pop-os#182 Signed-off-by: chris-010 <10660568+chris-010@users.noreply.github.com>
5 tasks done
mmstick
approved these changes
Aug 28, 2026
jklgrasso
approved these changes
Aug 28, 2026
jklgrasso
left a comment
There was a problem hiding this comment.
Sound plays after connecting or disconnecting the AC adapter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
watch_battery_plug_eventswatches only the first upower device whose name starts withline_power. Where a stale ACPI AC device is enumerated ahead of the supplies that actually work, the daemon watches that one forever and never sees a plug event.On a ThinkPad T490 (Pop!_OS 24.04) with the charger connected,
line_power_ACreportsOnline = falseand never changes, whileline_power_ucsi_source_psy_USBC000o001reportstrueand/sys/class/power_supply/AC/onlinereads 1.line_power_ACis enumerated first, sois_on_batterystaystrueand no plug event arrives — among other things the critical battery alert can then never be stopped by plugging in.This collects every
line_powerdevice and treats the machine as on mains power when any of them is online, recomputing across all of them when one changes. The debounce and the returned watch function are unchanged.Measured by logging the daemon's own
pw-playcalls while unplugging and replugging:power-unplugin the same secondpower-plugin the same secondline_power_AC.Onlinestayedfalsethroughout, so this works around the stale device rather than depending on it.Closes #182