i3status-rust icon indicating copy to clipboard operation
i3status-rust copied to clipboard

Battery: add `not_charging_format` config option

Open ram02z opened this issue 3 years ago • 22 comments

Battery config

[[block]]
block = "battery"
format = "{percentage:2}"
device = "BAT0"
allow_missing = true

i3status-rust version: 0.21.2 Linux kernel version: 5.15.17

image

This is all I see image

Using upower also has the same behaviour.

Let me know if there anything I can do to debug this issue.

ram02z avatar Jan 29 '22 13:01 ram02z

Can you check whether it works on the async branch (you'll need to adapt your format a little)?

MaxVerevkin avatar Jan 29 '22 13:01 MaxVerevkin

@MaxVerevkin

Im getting the following compile error:

error: linking with `cc` failed: exit status: 1
...
  = note: /usr/bin/ld: cannot find -lnotmuch
          /usr/bin/ld: cannot find -lsensors
          collect2: error: ld returned 1 exit status

Did the dependencies change?

I am using rust 1.57 and cargo 0.58.0

ram02z avatar Jan 29 '22 13:01 ram02z

If you use debian-based distro, run sudo apt-get install libsensors-dev libnotmuch-dev.

Did the dependencies change?

libsensors-dev is a new dependency, libnotmuch-dev will soon be optional.

MaxVerevkin avatar Jan 29 '22 13:01 MaxVerevkin

Can you check whether it works on the async branch (you'll need to adapt your format a little)?

Using the following config and the async branch

[[block]]
block = "battery"

The same behaviour is exhibited.

image

ram02z avatar Jan 29 '22 13:01 ram02z

Apparently the battery block treats "Not charging" as "Full": https://github.com/greshake/i3status-rust/blob/0cccc595b5c9bac940687dbe7a9e6ab6d42f0006/src/blocks/battery.rs#L857

MaxVerevkin avatar Jan 29 '22 13:01 MaxVerevkin

@ram02z What's the output of cat /sys/class/power_supply/BAT0/current_now?

MaxVerevkin avatar Jan 29 '22 13:01 MaxVerevkin

Apparently the battery block treats "Not charging" as "Full":

https://github.com/greshake/i3status-rust/blob/0cccc595b5c9bac940687dbe7a9e6ab6d42f0006/src/blocks/battery.rs#L857

I can confirm that when I disconnect the AC, the percentage is shown. Note that I am using a battery charging threshold, so it never reaches 100% and only starts charging when below 60%.

@ram02z What's the output of cat /sys/class/power_supply/BAT0/current_now?

current_now doesn't exist for me.

ram02z avatar Jan 29 '22 13:01 ram02z

I can confirm that when I disconnect the AC, the percentage is shown. Note that I am using a battery charging threshold, so it never reaches 100%.

Well, then the current output is correct?

MaxVerevkin avatar Jan 29 '22 13:01 MaxVerevkin

I can confirm that when I disconnect the AC, the percentage is shown. Note that I am using a battery charging threshold, so it never reaches 100%.

Well, then the current output is correct?

Not really, because if I plug it when its above the charging threshold but below the full capacity, e.g. 70%, it will not show the percentage.

image

ram02z avatar Jan 29 '22 13:01 ram02z

i3status-rust version: 0.21.2

Was it different in the previous versions?

MaxVerevkin avatar Jan 29 '22 13:01 MaxVerevkin

Was it different in the previous versions?

I did try 0.20.7 and 0.20.4 again to check, but the behaviour is the same, however, I am pretty sure this behaviour is new since I have always seen the percentage. I did update my Linux kernel yesterday, so that might be it.

Anyway, I set full_format = "{percentage}" and it shows now (According to the docs, this should the default behaviour, but I have had to set it explicitly). I still think the behaviour is weird, because the battery is flagged as full when in its in the range charge_control_start_thresh_hold < x <= charge_control_end_threshold and plugged in.

ram02z avatar Jan 29 '22 14:01 ram02z

So, in your case, battery should be considered full then it's 85% and above, discharging if it's between 60% and 85%, and charging if's below 60% and connected?

I did update my Linux kernel yesterday, so that might be it.

Most likely.

MaxVerevkin avatar Jan 29 '22 14:01 MaxVerevkin

So, in your case, battery should be considered full then it's 85% and above, discharging if it's between 60% and 85%, and charging if's below 60% and connected?

Yeah, the issue occurs when my AC is plugged in and my battery level is between 60% and 85%, it doesn't charge, but it doesn't discharge; remains at the original battery level when it was plugged in.

image

ram02z avatar Jan 29 '22 14:01 ram02z

Just to be sure, when the percentage drops to 60%, does the status change to "Charging"?

MaxVerevkin avatar Jan 29 '22 14:01 MaxVerevkin

Just to be sure, when the percentage drops to 60%, does the status change to "Charging"?

I think so, since I remember the icon changing to have the charging symbol. I am currently discharging my battery, I'll update you when it is < 60%.

ram02z avatar Jan 29 '22 14:01 ram02z

Also, it turns out that it was because of Linux 5.15.17. https://github.com/torvalds/linux/commit/dd7c1a93025284d244bb5b00108b7417df00e1df

ram02z avatar Jan 29 '22 14:01 ram02z

I think so, since I remember the icon changing to have the charging symbol. I am currently discharging my battery, I'll update you when it is < 60%.

Okay, if this is the case, then I think the block should just set status to "Discharging" if charge_control_start_thresh_hold < x <= charge_control_end_threshold && status == "Not charging" ?

MaxVerevkin avatar Jan 29 '22 14:01 MaxVerevkin

By the way, how does UPower handle this case?

 busctl get-property org.freedesktop.UPower /org/freedesktop/UPower/devices/battery_BAT0 org.freedesktop.UPower.Device State

MaxVerevkin avatar Jan 29 '22 14:01 MaxVerevkin

I think so, since I remember the icon changing to have the charging symbol. I am currently discharging my battery, I'll update you when it is < 60%.

Okay, if this is the case, then I think the block should just set status to "Discharging" if charge_control_start_thresh_hold < x <= charge_control_end_threshold && status == "Not charging" ?

Hmm, that would be better than "Full", but just "Not Charging" would be accurate.

By the way, how does UPower handle this case?

image image

ram02z avatar Jan 29 '22 14:01 ram02z

Hmm, that would be better than "Full", but just "Not Charging" would be accurate.

Like not_charging_format config option?

MaxVerevkin avatar Jan 29 '22 14:01 MaxVerevkin

Hmm, that would be better than "Full", but just "Not Charging" would be accurate.

Like not_charging_format config option?

Yeah I can see that being useful.

ram02z avatar Jan 29 '22 14:01 ram02z

Just to be sure, when the percentage drops to 60%, does the status change to "Charging"?

Yeah it does, when it is plugged in.

image

ram02z avatar Jan 29 '22 15:01 ram02z