Fix OpenWrt rate/lease mapping and queue pending
This commit is contained in:
@@ -38,7 +38,11 @@ def _format_rate(rate: Any) -> str:
|
||||
return "?"
|
||||
if val <= 0:
|
||||
return "?"
|
||||
return f"{val / 1000:.1f}M"
|
||||
if val >= 1_000_000:
|
||||
return f"{val / 1_000_000:.1f}M"
|
||||
if val >= 1_000:
|
||||
return f"{val / 1_000:.1f}K"
|
||||
return f"{val:.0f}b"
|
||||
|
||||
|
||||
def _extract_wan_ip(wan: dict[str, Any]) -> str | None:
|
||||
@@ -128,6 +132,18 @@ def _extract_lease_name_map(leases: Any) -> dict[str, str]:
|
||||
return out
|
||||
|
||||
|
||||
def _extract_lease_name_map_fallback(raw: str) -> dict[str, str]:
|
||||
out: dict[str, str] = {}
|
||||
for line in raw.splitlines():
|
||||
parts = line.strip().split()
|
||||
if len(parts) < 4:
|
||||
continue
|
||||
_expiry, mac, _ipaddr, host = parts[:4]
|
||||
host = host if host != "*" else "unknown"
|
||||
out[str(mac).lower()] = str(host)
|
||||
return out
|
||||
|
||||
|
||||
def _extract_ifnames(wireless: dict[str, Any]) -> list[str]:
|
||||
ifnames: list[str] = []
|
||||
if not isinstance(wireless, dict):
|
||||
@@ -360,6 +376,8 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
|
||||
ifnames.extend(_extract_hostapd_ifnames(out_l))
|
||||
ifnames = sorted({name for name in ifnames if name})
|
||||
lease_name_map = _extract_lease_name_map(leases or {})
|
||||
if leases_fallback:
|
||||
lease_name_map.update(_extract_lease_name_map_fallback(leases_fallback))
|
||||
if ifnames:
|
||||
for ifname in ifnames:
|
||||
cmd_clients = ssh_cmd + ["ubus", "call", f"hostapd.{ifname}", "get_clients"]
|
||||
|
||||
Reference in New Issue
Block a user