Battery improve output

- colored capacity
- show model and manufacturer only if they exists
This commit is contained in:
lachtan
2022-07-19 21:18:18 +02:00
parent 8a39c68713
commit 1477843206

View File

@@ -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: