Thanks to visit codestin.com
Credit goes to github.com

Skip to content

internal/battery module calculates power consumption incorrectly #928

Description

@MatthewLavine

I was comparing the functionality of i3status and polybar and noticed that the battery consumption wattage calculation was wildly different between the applications.

See here (i3status on top, polybar underneath):
battery

Based on these numbers I believe that i3status is showing the correct output and polybar is incorrect.

Checking into the module sources, here is where polybar attempts to get the current battery power usage: https://github.com/jaagr/polybar/blob/master/src/modules/battery.cpp#L61

Note that it sets m_frate to "current_now" or "power_now", whichever exists. The problem is that these two files can contain different units. As outlined in i3status's battery module, "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"

https://github.com/i3/i3status/blob/master/src/print_battery_info.c#L152

Based on this I think polybar's module needs some extra complicated logic to perform the necessary conversions. If power_now exists, then it's value can be used (with an order of magnitude conversion) instead of calculating current usage based on (incorrect) voltage and current.

I'm a Go programmer myself otherwise I'd send a PR; but I can take a crack at it if no one else has any cycles :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions