-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBattery.py
More file actions
86 lines (73 loc) · 2.74 KB
/
Copy pathBattery.py
File metadata and controls
86 lines (73 loc) · 2.74 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# pip install psutil
# CTRL + J Terminal
import psutil
import time
import time
from TextToSpeech.Fast_DF_TTS import speak
import threading
from Alert import Alert
battery = psutil.sensors_battery()
def battery_Alert():
while True:
time.sleep(3)
percentage = int(battery.percent)
if percentage == 100:
t1 = threading.Thread(target=Alert,args=("100%charge",))
t2 = threading.Thread(target=speak,args=("100% charged. Please unplug it.",))
t1.start()
t2.start()
t1.join()
t2.join()
elif percentage <= 20:
t1 = threading.Thread(target=Alert,args=("Battery Low",))
t2 = threading.Thread(target=speak,args=("Sir,Sorry to disturb you but battery is Low now",))
t1.start()
t2.start()
t1.join()
t2.join()
elif percentage <=10:
t1 = threading.Thread(target=Alert,args=("Battery is too Low",))
t2 = threading.Thread(target=speak,args=("Sir,Sorry to disturb you but we are running on very low battery power",))
t1.start()
t2.start()
t1.join()
t2.join()
elif percentage <= 5:
t1 = threading.Thread(target=Alert,args=("Battery is going to died",))
t2 = threading.Thread(target=speak,args=("Sir,Sorry to disturb you but this is your last chance sir , charge your system now",))
t1.start()
t2.start()
t1.join()
t2.join()
time.sleep(10)
def check_plug():
print("_____started___")
battery = psutil.sensors_battery()
previous_state = battery.power_plugged
while True:
battery = psutil.sensors_battery()
if battery.power_plugged != previous_state:
if battery.power_plugged:
t1 = threading.Thread(target=Alert,args=("Charging **STARTED**",))
t2 = threading.Thread(target=speak,args=("Charging Started",))
t1.start()
t2.start()
t1.join()
t2.join()
else:
t1 = threading.Thread(target=Alert,args=("Charging **STOP**",))
t2 = threading.Thread(target=speak,args=("Charging Stop",))
t1.start()
t2.start()
t1.join()
t2.join()
previous_state = battery.power_plugged
def check_percentage():
battery = psutil.sensors_battery()
percent = int(battery.percent)
t1 = threading.Thread(target=Alert,args=(f"The device is running on {percent}% power",))
t2 = threading.Thread(target=speak,args=(f"The device is running on {percent}% power",))
t1.start()
t2.start()
t1.join()
t2.join()