Finished a first version with basic outputs
This commit is contained in:
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"python.analysis.extraPaths": [
|
||||
"./alert-scheduler/src"
|
||||
]
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
"jobType": "cyclic",
|
||||
"jobFunction": "output_alerts",
|
||||
"dtTimeDelta": {
|
||||
"seconds": 5
|
||||
"seconds": 10
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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...")
|
||||
BIN
alert-scheduler/src/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
alert-scheduler/src/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
alert-scheduler/src/__pycache__/alert.cpython-310.pyc
Normal file
BIN
alert-scheduler/src/__pycache__/alert.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
8
alert-scheduler/src/alert.py
Normal file
8
alert-scheduler/src/alert.py
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
class Alert():
|
||||
message = ""
|
||||
|
||||
def __init__(self,message) -> None:
|
||||
self.message = message
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
alerts = []
|
||||
@@ -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()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from globals import alerts
|
||||
from __init__ import alerts
|
||||
|
||||
class updateAlerts:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user