Battery improve output
- colored capacity - show model and manufacturer only if they exists
This commit is contained in:
35
bin/battery
35
bin/battery
@@ -25,15 +25,15 @@ CYAN = '0;36'
|
||||
|
||||
|
||||
BatteryInfo = namedtuple(
|
||||
'BatteryInfo',
|
||||
'BatteryInfo',
|
||||
[
|
||||
'name',
|
||||
'name',
|
||||
'model',
|
||||
'manufacturer',
|
||||
'technology',
|
||||
'capacity',
|
||||
'status',
|
||||
'currrent_percent',
|
||||
'technology',
|
||||
'capacity',
|
||||
'status',
|
||||
'currrent_percent',
|
||||
'time_to_empty',
|
||||
'charging_current'
|
||||
]
|
||||
@@ -78,8 +78,8 @@ def read_battery(filename):
|
||||
def load_battery_info(info):
|
||||
return BatteryInfo(
|
||||
name = info['POWER_SUPPLY_NAME'],
|
||||
model = info['POWER_SUPPLY_MODEL_NAME'],
|
||||
manufacturer = info['POWER_SUPPLY_MANUFACTURER'],
|
||||
model = info.get('POWER_SUPPLY_MODEL_NAME', ''),
|
||||
manufacturer = info.get('POWER_SUPPLY_MANUFACTURER', ''),
|
||||
technology = info['POWER_SUPPLY_TECHNOLOGY'],
|
||||
capacity = float(info['POWER_SUPPLY_CHARGE_FULL']) / 1e6,
|
||||
status = info['POWER_SUPPLY_STATUS'],
|
||||
@@ -115,8 +115,23 @@ def format_time_to_empty(info):
|
||||
return terminal_colored(f"{hours}:{minutes:02d}", CYAN)
|
||||
|
||||
|
||||
def battery_model(info):
|
||||
model = ''
|
||||
if info.model:
|
||||
model += info.model
|
||||
if info.manufacturer:
|
||||
if model:
|
||||
model += ' - '
|
||||
model += info.manufacturer
|
||||
if model:
|
||||
model += ': '
|
||||
return model
|
||||
|
||||
|
||||
def print_battery_detail(info):
|
||||
print(f"Battery: {info.model} - {info.manufacturer}: {info.technology} {info.capacity} Ah")
|
||||
model = battery_model(info)
|
||||
capacity = terminal_colored(str(info.capacity), YELLOW)
|
||||
print(f"Battery: {model}{info.technology} {capacity} Ah")
|
||||
print("Battery level: " + format_percent(info))
|
||||
print("Battery status: " + format_status(info))
|
||||
if info.status == DISCHARNGING:
|
||||
@@ -163,7 +178,7 @@ if __name__ == '__main__':
|
||||
|
||||
|
||||
"""
|
||||
cat /sys/class/power_supply/cw2015-battery/uevent
|
||||
cat /sys/class/power_supply/cw2015-battery/uevent
|
||||
POWER_SUPPLY_NAME=cw2015-battery
|
||||
POWER_SUPPLY_TYPE=Battery
|
||||
POWER_SUPPLY_CAPACITY=100
|
||||
|
||||
Reference in New Issue
Block a user