From 377f339e57f53a071d297b4fe957323f01266b05 Mon Sep 17 00:00:00 2001 From: nils Date: Sun, 25 Feb 2024 11:53:48 +0100 Subject: [PATCH] Finished a first version with basic outputs --- .vscode/settings.json | 5 ++ alert-scheduler/config/runCfg.json | 2 +- alert-scheduler/src/__init__.py | 10 ++++ .../src/__pycache__/__init__.cpython-310.pyc | Bin 0 -> 484 bytes .../src/__pycache__/alert.cpython-310.pyc | Bin 0 -> 461 bytes .../__pycache__/output_alerts.cpython-310.pyc | Bin 831 -> 1816 bytes .../__pycache__/update_alerts.cpython-310.pyc | Bin 783 -> 779 bytes alert-scheduler/src/alert.py | 8 ++++ alert-scheduler/src/globals.py | 1 - alert-scheduler/src/output_alerts.py | 45 ++++++++++++++++-- alert-scheduler/src/update_alerts.py | 2 +- 11 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 alert-scheduler/src/__pycache__/__init__.cpython-310.pyc create mode 100644 alert-scheduler/src/__pycache__/alert.cpython-310.pyc create mode 100644 alert-scheduler/src/alert.py delete mode 100644 alert-scheduler/src/globals.py 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 0000000000000000000000000000000000000000..b84a1a7ae5d7992edaee3c8b1f654f071954177d GIT binary patch literal 484 zcmY+B%T60H6o!vIw7^N54$wRpq zCtyqck!|3`z0UJODed_}E0gCgK6;*8KPsfWEXu3Hug4eI8eew3i_fQL$6ro%TvBSK zu(U2|mX}hP>Nm9G4%*4%ep=}oQzfKHIbNgGP5S?pwoO?fU;0-`O-75Iq*LSX6WS&49PGU(J>v9zZJ5G5C8xG literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..f1cc468a0946fa4cce30afdf850389253af75512 GIT binary patch literal 461 zcmY*UJ5Izf5ValWqln#N%e_Gg)-44>APTxPbZM+8Hk(NKEOr6{ZO7h$GjJtSatkVE z9D%|}^Lw7>c{8k5DFJ)me(E0b7dA@^pt%OO8whtq5k*hnZ>%7S-IFY+0RLxyj4i;L z6jYIdDOv<7Qe1^6UT_rvGj`!ktIg<$i;Ny8)8`di{Dd|7Ex1LIM|va@6abgz8Fg`| ztu6ODV~$(hJ{S%|AH+nEzAr>QbXxRHYlYHJx*ZPUxg4un4SP}I-g8^kT1`+2YpNOB z9bQ}_Wz#pKlp!ug1u1=9d#StMr;HgqGtWXC@5@e0=~5}X0Y8NLOv=ZpZ08p*%p^eY m+7=;3j6%RQ7KJB-(>3!L-01US9w!WvTyi<@xBsN07vfqYusZ`{0li$eb37Rn_$Uro;~*S`~BWW)owQljCY^>qyF{@`4<upQg0WQbuvj3a`&o?sTv4Q~yUIx%5wo^xv{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Tu1Lq?{vDt*( ILWFDL2RqqLAOHXW diff --git a/alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc b/alert-scheduler/src/__pycache__/update_alerts.cpython-310.pyc index e1e66a3a24af841c120b3bc458d586d3c9e42608..46a6d57c7286063745456e6b7ab7a04ae258b486 100644 GIT binary patch delta 32 lcmeBY>t^H4=jG*M0D|S>w^QG3u2N5=jG*M0D@HE+o^9i@*ZL0yv3fLlb@8BQ#|<^lPLhRHw#_> 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: