From 93f023dda36470a629d723bc06856f70d3a2fc7b Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Thu, 13 Mar 2025 19:32:17 +0300 Subject: [PATCH] [+] fix percentage --- deps/com.github.aiortc.aiortc | 2 +- python/online/fxreader/pr34/commands.py | 26 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/deps/com.github.aiortc.aiortc b/deps/com.github.aiortc.aiortc index e1778f2..d3cdc32 160000 --- a/deps/com.github.aiortc.aiortc +++ b/deps/com.github.aiortc.aiortc @@ -1 +1 @@ -Subproject commit e1778f22d5f5ab5c1025191dd7faa35c653ce45b +Subproject commit d3cdc32f8c474d90e48ecc4729c0088999cb82ad diff --git a/python/online/fxreader/pr34/commands.py b/python/online/fxreader/pr34/commands.py index a2b124e..6cac2d2 100644 --- a/python/online/fxreader/pr34/commands.py +++ b/python/online/fxreader/pr34/commands.py @@ -2286,6 +2286,26 @@ def desktop_services(argv): else: return 0 + @property + def percentage_low(self) -> int: + try: + return int(subprocess.check_output(r''' + cat /etc/UPower/UPower.conf | grep -Po '^PercentageLow=\d+' + ''', shell=True,).decode('utf-8').strip().split('=')[1]) + except: + logger.exception('') + return 15 + + @property + def percentage_critical(self) -> int: + try: + return int(subprocess.check_output(r''' + cat /etc/UPower/UPower.conf | grep -Po '^PercentageCritical=\d+' + ''', shell=True,).decode('utf-8').strip().split('=')[1]) + except: + logger.exception('') + return 10 + def check(self): try: if not self.check_is_needed(): @@ -2303,18 +2323,18 @@ def desktop_services(argv): ] t3 = float(t2[0].split(':')[1].strip()[:-1]) t5 = any(['discharging' in o.lower() for o in t4]) - if t3 < 10 and t5: + if t3 < self.percentage_critical and t5: logging.error(json.dumps(dict( msg='too low', t3=t3, t5=t5 ))) subprocess.check_call(['systemctl', 'suspend']) - elif t3 < 15 and t5: + elif t3 < self.percentage_low and t5: msg = 'battery near low' logging.error(json.dumps(dict( msg=msg, t3=t3, t5=t5 ))) subprocess.check_call([ - 'notify-send', '-t', '%d' % (5 * 1000), msg + 'notify-send', '-t', '%d' % (5 * 1000), msg, '% 5.2f' % t3, ]) else: pass