# fabledscryer/core/widgets.py # # Central widget registry. Each entry describes one widget type that can be # placed on a dashboard. Plugin widgets declare which plugin must be enabled # for the widget to be available. # # Forward-compatibility notes: # - Step 8 (widget variants) will add multiple entries per plugin and a # "variant" sub-key rather than one entry per plugin. # - Step 9 (plugin management) will allow external plugins to register # entries here at load time via register_widget(). from __future__ import annotations WIDGET_REGISTRY: dict[str, dict] = { "ping": { "key": "ping", "label": "Ping", "description": "Live ping status and latency history for all monitored hosts", "hx_url": "/ping/rows", "detail_url": "/ping/", "plugin": None, # built-in; always available "poll": True, }, "dns": { "key": "dns", "label": "DNS", "description": "DNS resolution status for all monitored hosts", "hx_url": "/dns/rows", "detail_url": "/dns/", "plugin": None, "poll": True, }, "traefik": { "key": "traefik", "label": "Traefik", "description": "Proxy request rates, service health, and recent errors", "hx_url": "/plugins/traefik/widget", "detail_url": "/plugins/traefik/", "plugin": "traefik", "poll": True, }, "unifi": { "key": "unifi", "label": "UniFi Network", "description": "WAN status, client counts, active alarms", "hx_url": "/plugins/unifi/widget", "detail_url": "/plugins/unifi/", "plugin": "unifi", "poll": True, }, "ups": { "key": "ups", "label": "UPS", "description": "Battery charge, runtime estimate, load percentage", "hx_url": "/plugins/ups/widget", "detail_url": "/plugins/ups/", "plugin": "ups", "poll": True, }, } def register_widget(definition: dict) -> None: """Register a widget at runtime (used by external plugins in step 9).""" WIDGET_REGISTRY[definition["key"]] = definition def get_available_widgets(plugins_cfg: dict) -> list[dict]: """Return widgets whose plugin dependency is satisfied.""" result = [] for w in WIDGET_REGISTRY.values(): if w["plugin"] is None: result.append(w) elif plugins_cfg.get(w["plugin"], {}).get("enabled", False): result.append(w) return result