-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
22 lines (20 loc) · 998 Bytes
/
utils.py
File metadata and controls
22 lines (20 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
SETTINGS_PERCENTAGE_PATH = "/tmp/BatteryChargePercentage"
CHARGING_PERCENTAGE_PATH = "/sys/class/power_supply/BAT1/charge_control_end_threshold"
def get_charging_percentage():
with open(CHARGING_PERCENTAGE_PATH, "rt") as file:
battery_percentage = file.read()
return int(battery_percentage)
def set_charging_percentage(percentage:int):
last_percentage = get_charging_percentage()
if last_percentage == percentage:
print(f"No need to set the percentage. Required:{percentage}, Current:{last_percentage}")
return True
command = f"echo {percentage} | pkexec tee {CHARGING_PERCENTAGE_PATH}"
os.system(command)
battery_percentage = get_charging_percentage()
if int(battery_percentage) != percentage:
print(f"Unable to set the percentage. Required:{percentage}, Current:{battery_percentage}")
return False
print(f"Battery charge percentage changed from:{last_percentage} to:{battery_percentage}")
return True