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

battery.status isCharging always shows false in WINDOWS #541

Closed
irm19 opened this issue Feb 24, 2020 · 3 comments
Closed

battery.status isCharging always shows false in WINDOWS #541

irm19 opened this issue Feb 24, 2020 · 3 comments

Comments

@irm19
Copy link
Contributor

irm19 commented Feb 24, 2020

Hello,

I have noticed that battery.status['isCharging'] was false in my computer while it was connected.

The problem is related to line 22 in file https://github.com/kivy/plyer/blob/master/plyer/platforms/win/battery.py

    status["isCharging"] = query["BatteryFlag"] == 8

The problem is that "BatteryFlag" is actually a byte composed of multiple bits, see..
https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-system_power_status
so if multiple conditions apply, previous value would tend to be false... (in my case it was 'low battery' and 'charging') :-)

So my proposal is to consider somethin like

     status["isCharging"] = query["BatteryFlag"] & 8 > 0

However, that would still generate issues when BatteryFlag is 255 (Unknown)... so maybe...

     status["isCharging"] = query["BatteryFlag"] !=255 and query["BatteryFlag"] & 8 > 0

There are multiple options to handle this case... :-)

Keep up!!

@ghost
Copy link

ghost commented Mar 22, 2020

Hello! I suggest you to open a pull request with these changes, so they can be tested and eventually merged.

@irm19
Copy link
Contributor Author

irm19 commented Mar 27, 2020

Associated pull request #546.
For some unknown reason, it is not passing the "Ubuntu" styles. I assume something else must be wrong in the ubuntu construction, as the file modified is in the Windows side.

@Zen-CODE
Copy link
Member

Closed by the above merge. Thanks

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

No branches or pull requests

2 participants