Skip to content

Commit

Permalink
Add support for batteries outputting Time to empty on linux (i3#378)
Browse files Browse the repository at this point in the history
* Add support for batteries outputting Time to empty on linux

The battery in the pinebook pro does not output the remaining charge
in Wh or mAh, so i3 cannot calculate the time remaining. However, it
does directly output the number of minutes remaining on in
POWER_SUPPLY_TIME_TO_EMPTY. This adds support for reading this field
and converting it to seconds_remaining.

* Add testcase for POWER_SUPPLY_TIME_TO_EMTY_NOW
  • Loading branch information
C-Elegans authored Jun 15, 2020
1 parent 09358d2 commit e19539e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/print_battery_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ static bool slurp_battery_info(struct battery_info *batt_info, yajl_gen json_gen
batt_info->present_rate = abs(atoi(walk + 1));
else if (BEGINS_WITH(last, "POWER_SUPPLY_VOLTAGE_NOW="))
voltage = abs(atoi(walk + 1));
else if (BEGINS_WITH(last, "POWER_SUPPLY_TIME_TO_EMPTY_NOW="))
batt_info->seconds_remaining = abs(atoi(walk + 1)) * 60;
/* on some systems POWER_SUPPLY_POWER_NOW does not exist, but actually
* it is the same as POWER_SUPPLY_CURRENT_NOW but with μWh as
* unit instead of μAh. We will calculate it as we need it
Expand Down
4 changes: 4 additions & 0 deletions testcases/026-battery-time-to-empty/BAT0_uevent
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=655
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=2390000
1 change: 1 addition & 0 deletions testcases/026-battery-time-to-empty/expected_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BAT 30.64% 10:55
10 changes: 10 additions & 0 deletions testcases/026-battery-time-to-empty/i3status.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
general {
output_format = "none"
}

order += "battery 0"

battery 0 {
format = "%status %percentage %remaining"
path = "testcases/026-battery-time-to-empty/BAT0_uevent"
}

0 comments on commit e19539e

Please sign in to comment.