From: Plom Heller Date: Thu, 17 Sep 2026 09:00:52 +0000 (+0200) Subject: Minor code reorganization. X-Git-Url: https://plomlompom.com/repos/add_task?a=commitdiff_plain;h=c58a7b2caaed1562e9ca5b6b17e462a426ab862c;p=confplom Minor code reorganization. --- diff --git a/home/user/.config/sway/status.py b/home/user/.config/sway/status.py index 7abe81f..303a5b3 100755 --- a/home/user/.config/sway/status.py +++ b/home/user/.config/sway/status.py @@ -30,7 +30,33 @@ def int_at_path( return int(stripped_text) -def network_info( +def info_battery( + ) -> str: + 'Produce battery charge, status, health status bar text.' + path_battery = next(PATH_POWER_SUPPLY.glob(GLOB_BATTERY)) + status = BATTERY_STATUS_SYMBOLS.get( + (path_battery / 'status').read_text(encoding='utf8').strip(), + '?') + charge_pc, health_pc = -1, -1 + for prefix in ('charge', 'energy'): + path_full = path_battery / f'{prefix}_full' + if path_full.exists(): + full = int_at_path(path_full) + full_design = int_at_path(path_battery / f'{prefix}_full_design') + now = int_at_path(path_battery / f'{prefix}_now') + charge_pc = round(now / full * 100) + health_pc = round(full / full_design * 100) + break + return f'{charge_pc}%{status}{health_pc}%' + + +def info_datetime( + ) -> str: + 'Produce current date and time.' + return str(datetime.now().isoformat(' ', 'seconds')) + + +def info_network( ) -> tuple[str, ...]: 'Produce one status block full_text per connected ethernet/wifi interface.' def nmcli_fields( @@ -84,40 +110,21 @@ def network_info( return texts if texts else ('offline', ) -def battery_info( +def info_thermal( ) -> str: - 'Produce battery charge, status, health status bar text.' - path_battery = next(PATH_POWER_SUPPLY.glob(GLOB_BATTERY)) - status = BATTERY_STATUS_SYMBOLS.get( - (path_battery / 'status').read_text(encoding='utf8').strip(), - '?') - charge_pc, health_pc = -1, -1 - for prefix in ('charge', 'energy'): - path_full = path_battery / f'{prefix}_full' - if path_full.exists(): - full = int_at_path(path_full) - full_design = int_at_path(path_battery / f'{prefix}_full_design') - now = int_at_path(path_battery / f'{prefix}_now') - charge_pc = round(now / full * 100) - health_pc = round(full / full_design * 100) - break - return f'{charge_pc}%{status}{health_pc}%' + 'Produce Celsius of current device hotness.' + return str(round(max(int_at_path(path) + for path in PATH_THERMAL.glob(GLOB_THERMAL)) / 1000) + ) + '°C' if __name__ == '__main__': print(json_dumps(METADATA)) print('[', end='') - full_texts: list[str] = [] while True: - full_texts.clear() - full_texts += list(network_info()) - full_texts += [battery_info()] - full_texts += [ - str(round(max(int_at_path(path) - for path in PATH_THERMAL.glob(GLOB_THERMAL) - ) / 1000)) - + '°C'] - full_texts += [str(datetime.now().isoformat(' ', 'seconds'))] - print(json_dumps([{'full_text': text} for text in full_texts]), + print(json_dumps([{'full_text': text} + for text in info_network() + (info_battery(), + info_thermal(), + info_datetime())]), end=',\n', flush=True) sleep(1)