This commit is contained in:
Lars Nolden
2026-07-24 13:57:13 +02:00
parent fc8813c14a
commit 50a9ee8c58
16 changed files with 206 additions and 32 deletions
+27
View File
@@ -18,6 +18,7 @@ from rich.console import Group
from rich.table import Table
from rich.text import Text
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.containers import Horizontal, Vertical, VerticalScroll
from textual.message import Message
from textual.screen import ModalScreen
@@ -41,6 +42,19 @@ def rel_time(ts: float) -> str:
return f"{d // 3600}h {(d % 3600) // 60}m ago"
def fmt_duration(seconds: Optional[float]) -> str:
if seconds is None:
return "?"
s = int(round(seconds))
if s < 60:
return f"{s}s"
if s < 3600:
return f"{s // 60}m {s % 60:02d}s"
if s < 86400:
return f"{s // 3600}h {(s % 3600) // 60:02d}m"
return f"{s // 86400}d {(s % 86400) // 3600:02d}h"
def stream_text(ts_str: str, ev: dict) -> Text:
if ev.get("type") == "json":
fields = ev.get("fields", {})
@@ -109,6 +123,8 @@ class OmsApp(App[None]):
("a", "show_all", "Show all / stream"),
("enter", "select", "Select device"),
("q", "quit", "Quit"),
# priority so Ctrl+C quits even while a modal Input is focused
Binding("ctrl+c", "quit", "Quit", priority=True, show=False),
]
COLUMNS = [
@@ -337,6 +353,17 @@ class OmsApp(App[None]):
meta.add_row("link (C)", dev.c_field or "?")
meta.add_row("rssi", "?" if dev.rssi is None else f"{dev.rssi} dBm")
meta.add_row("telegrams", str(dev.count))
if dev.interval_samples >= 1:
est = fmt_duration(dev.interval_estimate)
last = fmt_duration(dev.interval_last)
detail = f"~{est}"
extra = f"last {last}, {dev.interval_samples} sample"
extra += "s" if dev.interval_samples != 1 else ""
interval_text = Text(detail, style="bold")
interval_text.append(f" ({extra})", style="dim")
meta.add_row("send interval", interval_text)
else:
meta.add_row("send interval", Text("— (need ≥2 telegrams)", style="dim"))
meta.add_row(
"first seen", time.strftime("%H:%M:%S", time.localtime(dev.first_seen))
)