summaryrefslogtreecommitdiff
path: root/external/plyer/platforms/win/libs/batterystatus.py
blob: ddb22cc788d99a8ba13ed201a4a105eb047d5a8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
__all__ = ('battery_status')


import ctypes
from plyer.platforms.win.libs import win_api_defs


def battery_status():
    status = win_api_defs.SYSTEM_POWER_STATUS()
    if not win_api_defs.GetSystemPowerStatus(ctypes.pointer(status)):
        raise Exception('Could not get system power status.')

    return dict((field, getattr(status, field)) for field, _ in status._fields_)