36 lines
1.1 KiB
Python
Executable File
36 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from distutils.util import strtobool
|
|
|
|
PATH_PRESENT = '/sys/class/power_supply/axp813-ac/present'
|
|
PATH_ONLINE = '/sys/class/power_supply/axp813-ac/online'
|
|
PATH_TYPE = '/sys/class/power_supply/axp813-ac/type'
|
|
PATH_HEALTH = '/sys/class/power_supply/axp813-ac/health'
|
|
PATH_INPUT_CURRENT_LIMIT = '/sys/class/power_supply/axp813-ac/input_current_limit'
|
|
PATH_VOLTAGE_MIN = '/sys/class/power_supply/axp813-ac/voltage_min'
|
|
|
|
present = False
|
|
with open(PATH_PRESENT, 'r') as f:
|
|
present = bool(strtobool(f.read().strip()))
|
|
|
|
online = False
|
|
with open(PATH_ONLINE, 'r') as f:
|
|
online = bool(strtobool(f.read().strip()))
|
|
|
|
result = {'present': present, 'online': online}
|
|
|
|
if present:
|
|
with open(PATH_TYPE, 'r') as f:
|
|
result['type'] = f.read().strip()
|
|
with open(PATH_HEALTH,'r') as f:
|
|
result['health'] = f.read().strip()
|
|
with open(PATH_INPUT_CURRENT_LIMIT, 'r') as f:
|
|
current = f.read().strip()
|
|
result['current'] = (int(current)/10000.0)*0.01
|
|
with open(PATH_VOLTAGE_MIN, 'r') as f:
|
|
voltage = f.read().strip()
|
|
result['voltage'] = (int(voltage)/10000.0)*0.01
|
|
|
|
import json
|
|
print(json.dumps(result))
|