Finished a first version with basic outputs

This commit is contained in:
2024-02-25 11:53:48 +01:00
parent 6ef8fee79a
commit 377f339e57
11 changed files with 67 additions and 6 deletions

View File

@@ -15,7 +15,7 @@
"jobType": "cyclic",
"jobFunction": "output_alerts",
"dtTimeDelta": {
"seconds": 5
"seconds": 10
}
},
{

View File

@@ -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...")

Binary file not shown.

View File

@@ -0,0 +1,8 @@
class Alert():
message = ""
def __init__(self,message) -> None:
self.message = message

View File

@@ -1 +0,0 @@
alerts = []

View File

@@ -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()

View File

@@ -1,4 +1,4 @@
from globals import alerts
from __init__ import alerts
class updateAlerts: