Add quiet hours, health checks, and logging
This commit is contained in:
@@ -205,6 +205,19 @@ def _extract_hostapd_ifnames(raw: str) -> list[str]:
|
||||
return ifnames
|
||||
|
||||
|
||||
def _net_label_for_ifname(ifname: str, ifname_meta: dict[str, dict[str, str]]) -> str:
|
||||
meta = ifname_meta.get(ifname, {})
|
||||
ssid = meta.get("ssid") or ""
|
||||
band = meta.get("band") or ""
|
||||
if ssid and band:
|
||||
return f"{ssid} ({band})"
|
||||
if ssid:
|
||||
return ssid
|
||||
if band:
|
||||
return band
|
||||
return ifname
|
||||
|
||||
|
||||
def _safe_json_load(raw: str) -> Any | None:
|
||||
if not raw:
|
||||
return None
|
||||
@@ -378,6 +391,7 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
||||
lease_name_map = _extract_lease_name_map(leases or {})
|
||||
if leases_fallback:
|
||||
lease_name_map.update(_extract_lease_name_map_fallback(leases_fallback))
|
||||
wifi_net_counts: dict[str, int] = {}
|
||||
if ifnames:
|
||||
for ifname in ifnames:
|
||||
cmd_clients = ssh_cmd + ["ubus", "call", f"hostapd.{ifname}", "get_clients"]
|
||||
@@ -387,6 +401,10 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
||||
if rc2 == 0:
|
||||
payload = _safe_json_load(out2)
|
||||
if payload:
|
||||
clients_payload = payload.get("clients") if isinstance(payload, dict) else None
|
||||
if isinstance(clients_payload, dict):
|
||||
label = _net_label_for_ifname(ifname, ifname_meta)
|
||||
wifi_net_counts[label] = wifi_net_counts.get(label, 0) + len(clients_payload)
|
||||
wifi_clients.extend(
|
||||
_parse_hostapd_clients(
|
||||
payload,
|
||||
@@ -407,8 +425,14 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
||||
f"⚙️ Load: {load}",
|
||||
f"🌐 WAN: {wan_ip} ({wan_state})",
|
||||
"",
|
||||
f"📶 Wi-Fi clients: {len(wifi_clients)}",
|
||||
]
|
||||
if wifi_net_counts:
|
||||
lines.append("📶 Wi-Fi networks:")
|
||||
for label, count in sorted(wifi_net_counts.items()):
|
||||
lines.append(f" - {label}: {count}")
|
||||
lines.append("")
|
||||
|
||||
lines.append(f"📶 Wi-Fi clients: {len(wifi_clients)}")
|
||||
if wifi_clients:
|
||||
for line in wifi_clients[:20]:
|
||||
lines.append(f" - {line}")
|
||||
|
||||
Reference in New Issue
Block a user