distatus / battery

cross-platform, normalized battery information library
MIT License
249 stars 36 forks source link

Add NotCharging state #16

Closed denysvitali closed 2 years ago

denysvitali commented 4 years ago

Apparently my notebook reports the Not Charging status as well, this PR adds the status so that the tool won't return an error when this status is seen.

dvitali@denvit-ws1:power_supply/BAT0 $ pwd
/sys/class/power_supply/BAT0
dvitali@denvit-ws1:power_supply/BAT0 $ cat status
Not Charging
KenjiTakahashi commented 3 years ago

Thanks for the PR! Indeed, it looks that such state exists in Linux specification. I am wondering why, though? What does it represent? Batteries are not "stable", they are always charging or discharging (or empty and not connected to power source). I don't want to expose some "artificial" state to the API, not without knowing what it means. Unfortunately, I couldn't find any details in kernel docs, maybe the source would shed some light? I'll try looking into it.

denysvitali commented 3 years ago

Well, I was impressed as well. Maybe it's due to the fact that some controllers are able to disable battery charging when they notice that the battery is fully charged, to avoid compromising the battery lifetime, therefore they disable the battery and solely rely on AC.

I mean, I'm not sure, this is just a wild guess :)

lnu commented 3 years ago

Same issue here. Under wsl in windows 10(ubuntu 20.04 lts)

KenjiTakahashi commented 2 years ago

I've been revisiting this code recently, as I'm working on a course about OS-level Go programming. [I've been meaning to do it for a long time anyway, but there were many other things happening, and this gave me some more push.]

There are few things of note here. After looking through the kernel code, it looks like the status (pseudo-)file can sometimes be RW. Apparently there are controllers that allow switching charging on/off through software. Which on Linux means writing state string to the status. That said, nowadays different drivers tend to use the "Not Charging" state more freely, e.g. to indicate stuff like described in #23.

Another thing I remembered is that OpenBSD also has similar state, called "battery idle". The package currently coerces it to Unknown.

Personally, I'm leaning towards the "Idle" name, it seems the most neutral to me. Doesn't provoke the question "Why?" in my head, like "Not Charging" or "On Hold". Either way, I plan to push some refactors in the coming days, that should also fix these issues.

denysvitali commented 2 years ago

Switching branches, closing this one.