Skip to content

Commit 41b4163

Browse files
authored
Allow users to specify battery device in config (#895)
1 parent 439f798 commit 41b4163

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

auto-cpufreq.conf-example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ turbo = auto
5151

5252
# settings for when using battery power
5353
[battery]
54+
# Specify which battery device to use for reading battery information. see available batteries by running: ls /sys/class/power_supply/
55+
# If not set, auto-cpufreq will automatically detect and use the first battery found
56+
# battery_device = BAT1
57+
5458
# see available governors by running: cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
5559
# preferred governor
5660
governor = powersave

auto-cpufreq.conf-example.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ services.auto-cpufreq.settings = {
5353

5454
# settings for when using battery power
5555
battery = {
56+
# Specify which battery device to use for reading battery information. see available batteries by running: ls /sys/class/power_supply/
57+
# If not set, auto-cpufreq will automatically detect and use the first battery found
58+
# battery_device = BAT1
59+
5660
# see available governors by running: cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
5761
# preferred governor
5862
governor = "powersave";

auto_cpufreq/modules/system_info.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,21 @@ def read_file(path: str) -> Optional[str]:
228228
@staticmethod
229229
def get_battery_path() -> Optional[str]:
230230

231+
# Check if user has specified a custom battery device in config
232+
if config.has_config():
233+
conf = config.get_config()
234+
if conf.has_option("battery", "battery_device"):
235+
battery_device = conf.get("battery", "battery_device").strip()
236+
if battery_device:
237+
custom_path = os.path.join(POWER_SUPPLY_DIR, battery_device)
238+
type_path = os.path.join(custom_path, "type")
239+
# Validate that the specified device exists and is a battery
240+
if os.path.isfile(type_path):
241+
content = SystemInfo.read_file(type_path)
242+
if content and content.lower() == "battery":
243+
return custom_path
244+
245+
# Fall back to auto-detection if no custom device specified or if it's invalid
231246
try:
232247
for entry in os.listdir(POWER_SUPPLY_DIR):
233248
path = os.path.join(POWER_SUPPLY_DIR, entry)

0 commit comments

Comments
 (0)