Skip to content

Add GetSystemPowerStatus wrapper#2010

Merged
mhammond merged 5 commits intomhammond:mainfrom
CristiFati:cfati_dev00
Feb 14, 2023
Merged

Add GetSystemPowerStatus wrapper#2010
mhammond merged 5 commits intomhammond:mainfrom
CristiFati:cfati_dev00

Conversation

@CristiFati
Copy link
Copy Markdown
Contributor

@CristiFati CristiFati commented Feb 4, 2023

Wrap [MS.Learn]: GetSystemPowerStatus function (winbase.h).

Test (build locally and overwrite the .pyd):

[cfati@CFATI-5510-0:e:\Work\Dev\GitHub\CristiFati\pywin32\src]> "e:\Work\Dev\VEnvs\py_pc064_03.10_test1_pw32\Scripts\python.exe" -c "import win32api as wapi;from pprint import pprint as pp;pp(wapi.GetSystemPowerStatus(), sort_dicts=0)"
{'ACLineStatus': 1,
 'BatteryFlag': 1,
 'BatteryLifePercent': 100,
 'SystemStatusFlag': 0,
 'BatteryLifeTime': 4294967295,
 'BatteryFullLifeTime': 4294967295}

Worth mentioning [SO]: In Python, how can I detect whether the computer is on battery power? (@CristiFati's answer) (contains explanation of a Python bug).

Note: Failed test seems to be caused by other files.

@CristiFati CristiFati closed this Feb 12, 2023
@CristiFati CristiFati reopened this Feb 12, 2023
@mhammond
Copy link
Copy Markdown
Owner

I've love to see this at least called by test_win32api, even if the values can't be sanely checked :). However:

'BatteryFullLifeTime': 4294967295}

MSDN documents the function returns -1, so this value is likely to confuse people. I wonder if we should manually handle this value as a special case?

Copy link
Copy Markdown
Owner

@mhammond mhammond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mhammond mhammond merged commit 49f8c20 into mhammond:main Feb 14, 2023
@CristiFati CristiFati deleted the cfati_dev00 branch February 17, 2024 00:02
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

Successfully merging this pull request may close these issues.

2 participants