Skip to content

Pin upower locale and parse all time units in omarchy-battery-status - #20699

Open
shuruheel wants to merge 1 commit into
omacom:quattrofrom
shuruheel:fix/battery-status-locale-and-seconds
Open

shuruheel wants to merge 1 commit into
omacom:quattrofrom
shuruheel:fix/battery-status-locale-and-seconds

Conversation

@shuruheel

Copy link
Copy Markdown
Contributor

What changes

Fixes two UPower output parsing bugs in bin/omarchy-battery-status:

  1. Comma-decimal locales truncate UPower metrics: upower -i calls setlocale(LC_ALL, "") and formats energy, energy-full, energy-full-design, energy-rate, capacity, and time to empty/time to full using the user's locale decimal separator (e.g., 13,9 W, 27,8 Wh, 2,0 hours under de_DE, fr_FR, es_ES, pt_BR, etc.). Because awk parses dot-decimals only, it truncated every number at the comma (13.9W → 13W, 0.9W → 0W triggering false charge_idle, 100% health → 98%).
  2. Sub-minute and multi-day UPower time units misparsed: libupower-glib formats time to full/time to empty in seconds, minutes, hours, or days. Line 63 only converted minute*, turning time to full: 45 seconds into 45h (and 1.5 days into 1h 30m). Additionally, default awk print (OFMT = "%.6g") truncated 15.5 / 60 and 30 / 3600 enough to round down by a minute (15m / 0m).

Changes

  • bin/omarchy-battery-status:
    • Pin LC_ALL=C on upower -i and upower -e (matching pactl, nmcli, rfkill, pacman, etc. elsewhere in bin/).
    • Convert second* ($4 / 3600), minute* ($4 / 60), and day* ($4 * 24) in upower_hours, emitting full precision via printf "%.17g".
  • test/shell.d/battery-status-test.sh:
    • Add comma-decimal upower stub tests (running under env -u LC_ALL -u LC_NUMERIC) asserting rate\t13.9W, health\t100%, time\t2h, and sub-1 W 0.9W (without false charge_idle).
    • Add duration unit tests verifying 45 seconds → 1m, 15.5 minutes → 16m, 2.5 hours → 2h 30m, and 1.5 days → 36h.

Verification

  • Verified 2-stage red-before / green-after: failed on unmodified upstream/quattro with rate 13W / health 98% / time 2h 5m before LC_ALL=C, and time 45h before the upower_hours unit fix; passed after both fixes.
  • bash test/shell.d/battery-status-test.sh — 14/14 passed
  • bash test/shell.d/battery-test.sh — 23/23 passed
  • bash -n bin/omarchy-battery-status test/shell.d/battery-status-test.sh — passed
  • ./test/cli — passed
  • Verified up_device_to_text unit strings in /usr/lib/libupower-glib.so and checked rounding across all 0.5..59.5 minutes and 1..59 seconds.

Screenshots

No visual change: CLI status helper only.

@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

omarchy-battery-status now reads UPower output under LC_ALL=C and converts seconds, minutes, and days with enough precision for minute rounding.

  • Battery status reads UPower decimal values consistently across locales.
  • Battery status converts every UPower time unit before showing remaining time.

Reviews (1) · Last reviewed commit: "Pin upower locale and parse all time uni..." · Reviewed by Greptile

@omarchybot omarchybot added the bug Something isn't working label Nov 28, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Codex (GPT-6.2 Sol High), Opus 5.5 High and muse-wonder via pi, thinking high checked the parser against UPower’s source. The C locale preserves decimal readings, and higher conversion precision rounds a 15.5-minute fallback to 16 minutes, a case that still rounds down in #10392. The \ fixture exercises the day conversion with a synthetic input, since UPower reports that duration in hours.

The preflight blocked worker verification, and GitHub Actions is waiting for maintainer approval.

@chessing234

Copy link
Copy Markdown
Contributor

your commit is in #21013, on omarchy-battery-status before the Surface cycle count and the charger draw. @dhh @omarchybot if 21013 lands, this can close as superseded.

@omarchybot

Copy link
Copy Markdown
Collaborator

Codex (GPT-6.2 Sol High) and Opus 5.5 High compared both diffs and agreed the locale and duration fix stands on its own. Reviewer independence is unverified. #21013 carries the same patch and regression tests in commit 5267c4fb, with the original authorship preserved.

Worker verification is still blocked by preflight, and GitHub Actions still requires maintainer approval.

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.

3 participants