Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of POWER_SUPPLY_TIME_TO_* properties #504

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/print_battery_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ static bool slurp_battery_info(battery_info_ctx_t *ctx, struct battery_info *bat
const char *walk, *last;
bool watt_as_unit = false;
int voltage = -1;
int seconds_remaining;
char batpath[512];
sprintf(batpath, path, number);
INSTANCE(batpath);
Expand Down Expand Up @@ -175,8 +176,17 @@ static bool slurp_battery_info(battery_info_ctx_t *ctx, struct battery_info *bat
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;
else if (BEGINS_WITH(last, "POWER_SUPPLY_TIME_TO_EMPTY_NOW=")) {
seconds_remaining = abs(atoi(walk + 1));
if (seconds_remaining) {
batt_info->seconds_remaining = seconds_remaining;
}
} else if (BEGINS_WITH(last, "POWER_SUPPLY_TIME_TO_FULL_NOW=")) {
seconds_remaining = abs(atoi(walk + 1));
if (seconds_remaining) {
batt_info->seconds_remaining = seconds_remaining;
}
}
/* 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
3 changes: 2 additions & 1 deletion testcases/026-battery-time-to-empty/BAT0_uevent
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=655
POWER_SUPPLY_TIME_TO_EMPTY_NOW=39300
POWER_SUPPLY_TIME_TO_FULL_NOW=0
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=2390000
5 changes: 5 additions & 0 deletions testcases/026-battery-time-to-empty/BAT1_uevent
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
POWER_SUPPLY_STATUS=Charging
POWER_SUPPLY_TIME_TO_EMPTY_NOW=0
POWER_SUPPLY_TIME_TO_FULL_NOW=15600
POWER_SUPPLY_CHARGE_FULL_DESIGN=7800000
POWER_SUPPLY_CHARGE_NOW=2390000
2 changes: 1 addition & 1 deletion testcases/026-battery-time-to-empty/expected_output.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BAT 30.64% 10:55
BAT 30.64% 10:55 | CHR 30.64% 04:20
6 changes: 6 additions & 0 deletions testcases/026-battery-time-to-empty/i3status.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ general {
}

order += "battery 0"
order += "battery 1"

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

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