-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbattery.py
More file actions
65 lines (52 loc) · 1.93 KB
/
battery.py
File metadata and controls
65 lines (52 loc) · 1.93 KB
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
55
56
57
58
59
60
61
62
63
64
65
# coding: utf-8
'''Simple demo of using UIDevice to query the current battery state'''
from objc_util import *
import platform
class BatteryDisplay:
def __init__(self):
self.UIDevice = ObjCClass('UIDevice')
self.device = self.UIDevice.currentDevice()
self.device.setBatteryMonitoringEnabled_(True)
self.battery_states = {1: '🔋 unplugged', 2: '⚡️ charging', 3: '✅ full'}
def get_battery_info(self):
battery_percent = self.device.batteryLevel() * 100
state = self.device.batteryState()
return (battery_percent, state)
def display(self):
battery_percent, state = self.get_battery_info()
if state == 2:
print('⚡️ Charging...')
print('🔋 Battery level: %0.1f%%' % (battery_percent))
elif state == 3:
print('✅ Full...')
print('🔋 Battery level: %0.1f%%' % (battery_percent))
else:
print('🔌 Not charging...')
print('🔋 Battery level: %0.1f%%' % (battery_percent))
def __del__(self):
self.device.setBatteryMonitoringEnabled_(False)
class systemDisplay:
def __init__(self):
self.UIDevice = ObjCClass('UIDevice')
self.device = self.UIDevice.currentDevice()
self.iPhone = self.device.localizedModel()
self.software = self.device.systemVersion()
self.kernel = platform.system()
self.release = platform.release()
self.cpu = platform.uname()
def get_cpu_info(self):
info = self.cpu
if info[0] == 'Darwin':
cpu_info = info[3].split()[10]
return cpu_info
else:
return 'Unknown'
def display(self):
print('📱', self.iPhone, self.software)
print('📦', self.kernel, self.release)
print('🔧', self.get_cpu_info())
monitor = BatteryDisplay()
monitor.get_battery_info()
monitor.display()
system_info = systemDisplay()
system_info.display()