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(
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)