sane-sysload: fix battery logic to also work on Pinephone Pro (and more devices, generally)
This commit is contained in:
@@ -30,6 +30,7 @@ and some presets, encapsulating the above:
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
|
||||
from dataclasses import dataclass
|
||||
@@ -347,9 +348,18 @@ def try_battery_path(p: str) -> BatteryInfo | None:
|
||||
return BatteryInfo(ps.capacity, charges_per_hour, ps.status)
|
||||
|
||||
def try_all_batteries() -> BatteryInfo | None:
|
||||
p = try_battery_path("/sys/class/power_supply/axp20x-battery") # Pinephone
|
||||
if p is None:
|
||||
p = try_battery_path("/sys/class/power_supply/BAT0") # Thinkpad
|
||||
# Pinephone: /sys/class/power_supply/axp20x-battery
|
||||
# Pinephone Pro: /sys/class/power_supply/rk818-battery
|
||||
# Thinkpad: /sys/class/power_supply/BAT0
|
||||
#
|
||||
# some machines have other stuff in power_supply, like wireless mice, AC adapters, etc.
|
||||
# those devices [almost?] always lack one of the fields of the internal battery, like `capacity`,
|
||||
# and so are correctly ignored here.
|
||||
p = None
|
||||
for ps in os.listdir("/sys/class/power_supply"):
|
||||
p = try_battery_path(f"/sys/class/power_supply/{ps}")
|
||||
if p is not None:
|
||||
break
|
||||
|
||||
logger.debug(f"perc: {p.percent_charged if p else None}")
|
||||
logger.debug(f"charge: {p.percent_charged if p else None}")
|
||||
|
Reference in New Issue
Block a user