aboutsummaryrefslogtreecommitdiff
path: root/.config/eww/scripts/battery.py
blob: 79d3471af007fc5e574d66b93cc83aec717db027 (plain) (blame)
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
86
87
88
89
#!/usr/bin/env python3

import psutil
import argparse
import subprocess


def secs2hours(secs):
    mm, ss = divmod(secs, 60)
    hh, mm = divmod(mm, 60)
    return "%d:%02d:%02d" % (hh, mm, ss)


parser = argparse.ArgumentParser()
parser.add_argument('--c',
                    choices=('status', 'left-click', 'middle-click', 'right-click'),
                    dest='command',
                    default='status',
                    help='Allowed values are status, left-click, middle-click and right-click'
                    )
args = parser.parse_args()

battery = psutil.sensors_battery()
icon = ""
percent = int(battery.percent)
time_left = battery.secsleft
isPlugged = battery.power_plugged
remaining = secs2hours(time_left)

if args.command == "status":
    if isPlugged:
        if percent == 100:
            icon = "󰂅"
        elif percent > 89 and percent < 100:
            icon = "󰂋"
        elif percent > 79 and percent < 90:
            icon = "󰂊"
        elif percent > 69 and percent < 80:
            icon = "󰢞"
        elif percent > 59 and percent < 70:
            icon = "󰂉"
        elif percent > 49 and percent < 60:
            icon = "󰢝"
        elif percent > 39 and percent < 50:
            icon = "󰂈"
        elif percent > 29 and percent < 40:
            icon = "󰂇"
        elif percent > 19 and percent < 30:
            icon = "󰂆"
        elif percent > 9 and percent < 20:
            icon = "󰢜"
        elif percent > 0 and percent < 10:
            icon = "󰢟"
        message = str(percent) + "%"
        print(icon, message, end="")
    else:
        if percent == 100:
            icon = ""
        elif percent > 89 and percent < 100:
            icon = "󰂂"
        elif percent > 79 and percent < 90:
            icon = "󰂁"
        elif percent > 69 and percent < 80:
            icon = "󰂀"
        elif percent > 59 and percent < 70:
            icon = "󰁿"
        elif percent > 49 and percent < 60:
            icon = "󰁾"
        elif percent > 39 and percent < 50:
            icon = "󰁽"
        elif percent > 29 and percent < 40:
            icon = "󰁼"
        elif percent > 19 and percent < 30:
            icon = "󰁻"
        elif percent > 9 and percent < 20:
            icon = "󰁺"
        elif percent > 0 and percent < 10:
            icon = "󱃍"
        message = str(percent) + "%"
        print(icon, message, end="")
if args.command == "left-click":
    if not isPlugged:
        subprocess.call(["notify-send", "-r", "55555", "-u", "normal", "Est remaining time left: " + remaining])
    else:
        subprocess.call(["notify-send", "-r", "55555", "-u", "normal", str(percent) + "% Charged"])
if args.command == "middle-click":
    print("Middle click")
if args.command == "right-click":
    print("Right click")