diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4f73bf1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "python.analysis.extraPaths": [ + "./alert-scheduler/src" + ] +} \ No newline at end of file diff --git a/alert-scheduler/config/runCfg.json b/alert-scheduler/config/runCfg.json index d8fcab4..700d23c 100644 --- a/alert-scheduler/config/runCfg.json +++ b/alert-scheduler/config/runCfg.json @@ -15,7 +15,7 @@ "jobType": "cyclic", "jobFunction": "output_alerts", "dtTimeDelta": { - "seconds": 5 + "seconds": 10 } }, { diff --git a/alert-scheduler/src/__init__.py b/alert-scheduler/src/__init__.py index e69de29..39ecfe8 100644 --- a/alert-scheduler/src/__init__.py +++ b/alert-scheduler/src/__init__.py @@ -0,0 +1,10 @@ +import paho.mqtt.client as mqtt +from alert import Alert + +#alerts : Alert = [Alert("JUST A TEST1"),Alert("JUST A TEST2")] +alerts : Alert = [] + +client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) + +client.connect("192.168.178.36",1884,keepalive=60) +client.publish("watchdog/alerts/status","Watchdog-Alerts starting up...") \ No newline at end of file diff --git a/alert-scheduler/src/__pycache__/__init__.cpython-310.pyc b/alert-scheduler/src/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..b84a1a7 Binary files /dev/null and b/alert-scheduler/src/__pycache__/__init__.cpython-310.pyc differ diff --git a/alert-scheduler/src/__pycache__/alert.cpython-310.pyc b/alert-scheduler/src/__pycache__/alert.cpython-310.pyc new file mode 100644 index 0000000..f1cc468 Binary files /dev/null and b/alert-scheduler/src/__pycache__/alert.cpython-310.pyc differ diff --git a/alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc b/alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc index bd3ab1e..b8b0304 100644 Binary files a/alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc and b/alert-scheduler/src/__pycache__/output_alerts.cpython-310.pyc differ diff --git a/alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc b/alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc index e1e66a3..46a6d57 100644 Binary files a/alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc and b/alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc differ diff --git a/alert-scheduler/src/alert.py b/alert-scheduler/src/alert.py new file mode 100644 index 0000000..4e2893a --- /dev/null +++ b/alert-scheduler/src/alert.py @@ -0,0 +1,8 @@ + +class Alert(): + message = "" + + def __init__(self,message) -> None: + self.message = message + + \ No newline at end of file diff --git a/alert-scheduler/src/globals.py b/alert-scheduler/src/globals.py deleted file mode 100644 index 5ab4c56..0000000 --- a/alert-scheduler/src/globals.py +++ /dev/null @@ -1 +0,0 @@ -alerts = [] \ No newline at end of file diff --git a/alert-scheduler/src/output_alerts.py b/alert-scheduler/src/output_alerts.py index 25e2a21..d17ba1b 100644 --- a/alert-scheduler/src/output_alerts.py +++ b/alert-scheduler/src/output_alerts.py @@ -1,17 +1,56 @@ -from globals import alerts +from __init__ import alerts, client +from alert import Alert +import json class outputAlerts: alert_index = 0 - alerts = [] + alerts :Alert = [] + + AWTRIX_NOTIFY = "awtrix/notify" + DURATION = 5 def __init__(self) -> None: self.alert_index = 0 self._get_alerts() def print_next(self): - pass + + if len(self.alerts) < self.alert_index + 1: + self._get_alerts() + self.alert_index = 0 + + if len(self.alerts) == 0: + self._display_all_ok() + else: + self._display_next() + + def _display_next(self): + alert : Alert + alert = self.alerts[self.alert_index] + message = { + "text": alert.message, + "repeat": 1, + #"rainbow": True, + #"duration": self.DURATION + } + self.alert_index += 1 + self._send_message(message) + + def _display_all_ok(self): + message = { + "text": "Smarthome is all OK!", + "repeat": 1, + #"rainbow": True, + #"duration": self.DURATION + } + self._send_message(message) + + def _send_message(self,message): + if not client.is_connected(): + client.connect("192.168.178.36",1884,keepalive=60) + client.publish(self.AWTRIX_NOTIFY,json.dumps(message)) def _get_alerts(self): self.alerts = alerts.copy() diff --git a/alert-scheduler/src/update_alerts.py b/alert-scheduler/src/update_alerts.py index bf29ca7..de62aaa 100644 --- a/alert-scheduler/src/update_alerts.py +++ b/alert-scheduler/src/update_alerts.py @@ -1,4 +1,4 @@ -from globals import alerts +from __init__ import alerts class updateAlerts: