"""Shared drive-health classification. Single source of truth for turning a parsed SMART dict into a healthy/warning/error status, used by both the poller (host drives) and the API (enclosure drives) so the rule never drifts between them. """ def compute_health_status(smart: dict) -> str: """Return "healthy", "warning", or "error" for a SMART dict.""" healthy = smart.get("smart_healthy") realloc = smart.get("reallocated_sectors") or 0 pending = smart.get("pending_sectors") or 0 unc = smart.get("uncorrectable_errors") or 0 supported = smart.get("smart_supported", True) if healthy is False: return "error" if realloc > 0 or pending > 0 or unc > 0 or (healthy is None and supported): return "warning" return "healthy"