Browse Source

Battery bugfix

sisyphus
JezerM 3 years ago
parent
commit
eb1c28b09b
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 7
      web-greeter/utils/battery.py

7
web-greeter/utils/battery.py

@ -49,7 +49,8 @@ class Battery:
capacity = 0, capacity = 0,
)) ))
else: else:
self.ac = re.match(r"A\w+", line).group() or self.ac match = re.match(r"A\w+", line)
self.ac = match.group() if match else self.ac
# Based on "bat" widget from "lain" awesome-wm library # Based on "bat" widget from "lain" awesome-wm library
# * (c) 2013, Luca CPZ # * (c) 2013, Luca CPZ
@ -106,7 +107,7 @@ class Battery:
sum_charge_full = sum_charge_full + charge_full sum_charge_full = sum_charge_full + charge_full
sum_charge_design = sum_charge_design + charge_design sum_charge_design = sum_charge_design + charge_design
self.capacity = math.floor(min(100, sum_charge_full / sum_charge_design * 100)) self.capacity = math.floor(min(100, sum_charge_full / (sum_charge_design or 1) * 100))
self.status = len(self._batteries) > 0 and self._batteries[0]["status"] or "N/A" self.status = len(self._batteries) > 0 and self._batteries[0]["status"] or "N/A"
for i in range(len(self._batteries)): for i in range(len(self._batteries)):
@ -189,6 +190,7 @@ def acpi_listen(callback, onerror):
awky = subprocess.Popen(shlex.split("grep --line-buffered -E 'battery|ac_adapter'"), awky = subprocess.Popen(shlex.split("grep --line-buffered -E 'battery|ac_adapter'"),
stdout=subprocess.PIPE, stdin=main.stdout, text=True) stdout=subprocess.PIPE, stdin=main.stdout, text=True)
while True: while True:
if (awky.stdout == None): continue
output = awky.stdout.readline() output = awky.stdout.readline()
if output == "" and awky.poll() != None: if output == "" and awky.poll() != None:
break break
@ -209,6 +211,7 @@ def scandir_line(path, callback):
main = subprocess.Popen(shlex.split("ls -1 {}".format(path)), main = subprocess.Popen(shlex.split("ls -1 {}".format(path)),
stdout=subprocess.PIPE, text=True) stdout=subprocess.PIPE, text=True)
while True: while True:
if (main.stdout == None): continue
line = main.stdout.readline() line = main.stdout.readline()
if line == "" and main.poll() != None: if line == "" and main.poll() != None:
break break

Loading…
Cancel
Save