Files
buzzer/buzzer_tool/core/commands/info.py
2026-02-27 17:07:07 +01:00

38 lines
1.2 KiB
Python

# core/commands/info.py
from core.connection import BuzzerError
def execute(conn) -> dict:
"""Holt die Systeminformationen und gibt sie als strukturiertes Dictionary zurück."""
lines = conn.send_command("info")
if not lines:
raise BuzzerError("Keine Antwort auf 'info' empfangen.")
parts = lines[0].split(';')
# Auf 6 Parameter aktualisiert
if len(parts) != 6:
raise BuzzerError(f"Unerwartetes Info-Format: {lines[0]}")
protocol_version = int(parts[0])
if protocol_version != 2:
raise BuzzerError(f"Inkompatibles Protokoll: Gerät nutzt v{protocol_version}, Host erwartet v2.")
app_version = parts[1]
f_frsize = int(parts[2])
f_blocks = int(parts[3])
f_bfree = int(parts[4])
image_status = parts[5].strip() # CONFIRMED oder UNCONFIRMED
total_kb = (f_blocks * f_frsize) / 1024
free_kb = (f_bfree * f_frsize) / 1024
used_kb = total_kb - free_kb
percent_used = (used_kb / total_kb) * 100 if total_kb > 0 else 0
return {
"protocol_version": protocol_version,
"app_version": app_version,
"total_kb": total_kb,
"free_kb": free_kb,
"used_kb": used_kb,
"percent_used": percent_used,
"image_status": image_status
}