svartalf / rust-battery

Rust crate providing cross-platform information about the notebook batteries.
https://crates.io/crates/battery
Apache License 2.0
354 stars 40 forks source link

WSL support. #57

Closed rhubarbwu closed 4 years ago

rhubarbwu commented 4 years ago

rust-battery doesn't yet work in the Windows Subsystem for Linux (WSL). It isn't detecting any batteries.

svartalf commented 4 years ago

Oh, that's bad, thanks for a bug report! I'll try to check that tomorrow. In a meanwhile, can you provide an output of the following command, executed in the WSL env?

 find /sys/class/power_supply/battery/ -name '*' -print -exec cat {} \;
rhubarbwu commented 4 years ago

Sure thing! I'm running ArchWSL but I would imagine I'd get something similar in Debian/UbuntuWSL.

>find /sys/class/power_supply/battery/ -name '*' -print -exec cat {} \;
/sys/class/power_supply/battery/
cat: /sys/class/power_supply/battery/: Operation not permitted
/sys/class/power_supply/battery/capacity
98
/sys/class/power_supply/battery/charge_counter
3001
/sys/class/power_supply/battery/current_now
0
/sys/class/power_supply/battery/health
Good
/sys/class/power_supply/battery/present
1
/sys/class/power_supply/battery/status
Not charging
/sys/class/power_supply/battery/technology
Li-ion
/sys/class/power_supply/battery/temp
258
/sys/class/power_supply/battery/type
Battery
/sys/class/power_supply/battery/voltage_now
12659000

I can help with this issue, if you'd like.

svartalf commented 4 years ago

Based on the files available it should work as expected, as it has the same files as in #40 case: https://github.com/svartalf/rust-battery/blob/eb7727bdf562382e074ea099c3dfcdfb8b1e71d3/battery/src/platform/linux/tests/issue_40.rs#L17-L28

@leglesslamb if you want to hack on this issue, feel free to do that! I would start with a test case, similar to that one from above and based on your data.

rhubarbwu commented 4 years ago

I see. I was just getting None for many of the values when I used the example from your README.md.

Battery #0:
Vendor: None
Model: None
State: Unknown
Time to full charge: None

But actually using the crate in code, it seems to work. Thanks!