from typing import Literal, TypedDict TriageLevel = Literal["ignore", "log_only", "notify", "alarm"] class SecurityTriage(TypedDict): level: TriageLevel reason: str def triage_security_event(event_type: str, time_of_day: str, severity: str, away_mode: bool) -> SecurityTriage: """Very small rule-based triage for security events.""" et = event_type.lower() t = time_of_day.lower() sv = severity.lower() # Critical door/motion at night while away -> alarm if away_mode and t == "night" and et in {"door_open", "motion"} and sv in {"warning", "critical"}: return {"level": "alarm", "reason": "Unexpected movement or door open at night in away mode."} # Critical severity always at least notify if sv == "critical": return {"level": "notify", "reason": "Critical event; user should be notified."} # Warnings in away mode -> notify if away_mode and sv == "warning": return {"level": "notify", "reason": "Warning event while away; send notification."} # Info level -> log only if sv == "info": return {"level": "log_only", "reason": "Informational event; keep in log only."} return {"level": "ignore", "reason": "Low-importance event in home mode."} if __name__ == "__main__": tests = [ ("door_open", "night", "critical", True), ("sound", "night", "warning", True), ("motion", "afternoon", "info", False), ("unknown", "evening", "warning", False), ] for e in tests: print(e, "->", triage_security_event(*e))