This commit is contained in:
2026-08-11 18:16:49 +02:00
parent 1543dde603
commit 07051a7255
6 changed files with 127 additions and 9 deletions
+47
View File
@@ -0,0 +1,47 @@
import time
class AlertManager:
def __init__(self):
self.alerts = []
self.on_alert_callback = None
def set_on_alert_callback(self, callback):
self.on_alert_callback = callback
def add_alert(self, alert):
self.alerts.append(alert)
if self.on_alert_callback:
self.on_alert_callback(alert)
def get_alerts(self):
return self.alerts
def clear_alerts(self):
self.alerts.clear()
class Alert:
def __init__(self, alertType: "AlertType", message: str):
self.alertType = alertType
self.message = message
self.timestamp = time.time()
def to_dict(self):
return {
"type": self.alertType,
"message": self.message,
"timestamp": self.timestamp
}
def to_json(self):
import json
return json.dumps(self.to_dict())
def from_json(json_string: str) -> "Alert":
import json
data = json.loads(json_string)
alert = Alert(data["type"], data["message"])
alert.timestamp = data["timestamp"]
return alert
class AlertType:
COOKING_SAFETY = "COOKING_SAFETY"