| 1 | ''' |
| 2 | Module of Windows API helper for plyer.battery. |
| 3 | ''' |
| 4 | |
| 5 | __all__ = ('battery_status') |
| 6 | |
| 7 | |
| 8 | import ctypes |
| 9 | from plyer.platforms.win.libs import win_api_defs |
| 10 | |
| 11 | |
| 12 | def battery_status(): |
| 13 | ''' |
| 14 | Implementation of Windows system power status API for plyer.battery. |
| 15 | ''' |
| 16 | |
| 17 | status = win_api_defs.SYSTEM_POWER_STATUS() |
| 18 | if not win_api_defs.GetSystemPowerStatus(ctypes.pointer(status)): |
| 19 | raise Exception('Could not get system power status.') |
| 20 | |
| 21 | return dict( |
| 22 | (field, getattr(status, field)) |
| 23 | for field, _ in status._fields_ |
| 24 | ) |