| | 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() |
| |
|
| | |
| | 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."} |
| |
|
| | |
| | if sv == "critical": |
| | return {"level": "notify", "reason": "Critical event; user should be notified."} |
| |
|
| | |
| | if away_mode and sv == "warning": |
| | return {"level": "notify", "reason": "Warning event while away; send notification."} |
| |
|
| | |
| | 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)) |
| |
|