forked from xvxvdee/Windows11-BatteryAlerts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbattery_status.py
More file actions
54 lines (49 loc) · 2.11 KB
/
battery_status.py
File metadata and controls
54 lines (49 loc) · 2.11 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
from psutil import sensors_battery
from win11toast import toast
from pymsgbox import alert
from time import sleep
import keyboard
import os
charging_toast = 0
uncharged_toast = 0
in80charged_toast = 0
fullycharged_toast = 0
running = 1
def flip():
global running
running = not running
alert(f"Running status changed to: {bool(running)}", os.path.basename(__file__))
keyboard.add_hotkey('ctrl+shift+alt+o', flip)
while running:
battery = sensors_battery()
plugged = battery.power_plugged
percent = str(battery.percent)
if plugged and percent == '80' and charging_toast == 1 and in80charged_toast == 0:
charging_toast = 0
uncharged_toast = 0
in80charged_toast = 1
fullycharged_toast = 0
toast('Charging Status🔌', 'Laptop is still charging. Current charge: ' + percent + '%', button='Dismiss')
print(charging_toast, uncharged_toast, in80charged_toast, fullycharged_toast)
if plugged and percent != '100' and charging_toast == 0 and in80charged_toast == 0:
charging_toast = 1
uncharged_toast = 0
in80charged_toast = 0
fullycharged_toast = 0
toast('Charging Status🔌', 'Laptop is now charging. Current charge: ' + percent + '%', button='Dismiss')
print(charging_toast, uncharged_toast, in80charged_toast, fullycharged_toast)
if not plugged and percent != '100' and uncharged_toast == 0:
charging_toast = 0
uncharged_toast = 1
in80charged_toast = 0
fullycharged_toast = 0
toast('Charging Status🔌', 'Laptop is uncharged. Current charge: ' + percent + '%', button='Dismiss')
print(charging_toast, uncharged_toast, in80charged_toast, fullycharged_toast)
if plugged and percent == '100' and fullycharged_toast == 0:
charging_toast = 0
uncharged_toast = 0
in80charged_toast = 0
fullycharged_toast = 1
toast('Charging Status🔋', 'Fully charged! Unplug your laptop.', button='Dismiss')
print(charging_toast, uncharged_toast, in80charged_toast, fullycharged_toast)
sleep(1)