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

Add support for batteries outputting Time to empty on linux #378

Merged
merged 2 commits into from
Jun 15, 2020

Conversation

C-Elegans
Copy link
Contributor

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, so i3status can report the time remaining on the battery

@@ -173,6 +173,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="))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you maybe add a testcase for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, added test 026-battery-time-to-empty

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.
@C-Elegans C-Elegans force-pushed the master branch 2 times, most recently from 44e6b4e to 25ad137 Compare January 27, 2020 20:00
@rillian
Copy link

rillian commented Feb 3, 2020

What path do you have in your i3status.conf? I still get "No battery" with this patch. If I add path = "/sys/class/power_supply/%d-battery/uevent" to pick up the cw2015-battery device (%d is turned into a * glob) I get BAT 0.00% 00:00 or CHR 0,00%. That is, state is reflected but time remaining is not. Neither is percentage reported if I add a line parsing POWER_SUPPLY_CAPACITY.

This is with a local build of the tsys 5.5.0 kernel. Does your kernel report battery capacity differently?

@C-Elegans
Copy link
Contributor Author

@rillian I specify the full path to the battery, no substitution with %d:

 battery 0 {
        status_chr = " CHR"
        status_bat = " BAT"
        format = "%status %percentage %remaining %consumption"
        path = "/sys/class/power_supply/cw2015-battery/uevent"
        low_threshold = 20
        threshold_type = "percentage"
}

@palfrey
Copy link

palfrey commented Jun 5, 2020

Running into the same issue on my Pinebook Pro. Is there anything in particular I can do to aid this getting merged?

@AeroNotix
Copy link

damn I just forked to send this same PR! Oh well.

@stapelberg stapelberg merged commit e19539e into i3:master Jun 15, 2020
@stapelberg
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants