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 argparse
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from dataclasses import dataclass
|
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)
|
return BatteryInfo(ps.capacity, charges_per_hour, ps.status)
|
||||||
|
|
||||||
def try_all_batteries() -> BatteryInfo | None:
|
def try_all_batteries() -> BatteryInfo | None:
|
||||||
p = try_battery_path("/sys/class/power_supply/axp20x-battery") # Pinephone
|
# Pinephone: /sys/class/power_supply/axp20x-battery
|
||||||
if p is None:
|
# Pinephone Pro: /sys/class/power_supply/rk818-battery
|
||||||
p = try_battery_path("/sys/class/power_supply/BAT0") # Thinkpad
|
# 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"perc: {p.percent_charged if p else None}")
|
||||||
logger.debug(f"charge: {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