File: battery.py

package info (click to toggle)
python-plyer 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,808 kB
  • sloc: python: 13,395; sh: 217; makefile: 177
file content (54 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'''
Battery
=======

The :class:`Battery` provides information about the battery of your device.

.. note::
        On Android the `BATTERY_STATS` permission is needed.

Simple Example
---------------

To get battery status::

    >>> from plyer import battery
    >>> battery.status
    {'percentage': 82.0, 'isCharging': False}

Supported Platforms
-------------------
Android, iOS, Windows, OS X, Linux

'''


class Battery:
    '''
    Battery info facade.
    '''

    @property
    def status(self):
        '''
        Property that contains a dict with the following fields:
             * **isCharging** *(bool)*: Battery is charging
             * **percentage** *(float)*: Battery charge remaining

            .. warning::
                If any of the fields is not readable, it is set as
                None.
        '''
        return self.get_state()

    def get_state(self):
        '''
        Public method for filling battery.status via platform-specific
        API in plyer.platforms.
        '''
        return self._get_state()

    # private

    def _get_state(self):
        raise NotImplementedError()