mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-09 17:07:43 +01:00
aded sensor name and timestamp of last data to notification
This commit is contained in:
parent
85490cebc8
commit
9e50b790e0
3 changed files with 13 additions and 3 deletions
|
@ -1,3 +1,3 @@
|
|||
__version__ = "4.1.0.rc4"
|
||||
__version__ = "4.1.0.rc5"
|
||||
__codename__ = "Groundhog Day"
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import asyncio
|
|||
from aiohttp import web
|
||||
from cbpi.api import *
|
||||
import time
|
||||
from datetime import datetime
|
||||
import re
|
||||
import logging
|
||||
from cbpi.api.dataclasses import NotificationAction, NotificationType
|
||||
|
@ -21,6 +22,8 @@ class HTTPSensor(CBPiSensor):
|
|||
self.starttime = time.time()
|
||||
self.notificationsend = False
|
||||
self.nextchecktime=self.starttime+self.timeout
|
||||
self.sensor=self.get_sensor(self.id)
|
||||
self.lastdata=time.time()
|
||||
|
||||
async def Confirm(self, **kwargs):
|
||||
self.nextchecktime = time.time() + self.timeout
|
||||
|
@ -28,7 +31,8 @@ class HTTPSensor(CBPiSensor):
|
|||
pass
|
||||
|
||||
async def message(self):
|
||||
self.cbpi.notify("HTTPSensor Timeout", "Sensor " + str(self.id) + " did not respond", NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
|
||||
target_timestring= datetime.fromtimestamp(self.lastdata)
|
||||
self.cbpi.notify("HTTPSensor Timeout", "Sensor '" + str(self.sensor.name) + "' did not respond. Last data received: "+target_timestring.strftime("%D %H:%M"), NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
|
||||
pass
|
||||
|
||||
async def run(self):
|
||||
|
@ -50,6 +54,7 @@ class HTTPSensor(CBPiSensor):
|
|||
if self.timeout !=0:
|
||||
self.nextchecktime = currenttime + self.timeout
|
||||
self.notificationsend = False
|
||||
self.lastdata=time.time()
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
pass
|
||||
|
|
|
@ -6,6 +6,7 @@ from cbpi.api import *
|
|||
import logging
|
||||
import json
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
@parameters([Property.Text(label="Topic", configurable=True, description="MQTT Topic"),
|
||||
Property.Text(label="PayloadDictionary", configurable=True, default_value="",
|
||||
|
@ -26,6 +27,8 @@ class MQTTSensor(CBPiSensor):
|
|||
self.starttime = time.time()
|
||||
self.notificationsend = False
|
||||
self.nextchecktime=self.starttime+self.timeout
|
||||
self.lastdata=time.time()
|
||||
self.sensor=self.get_sensor(self.id)
|
||||
|
||||
async def Confirm(self, **kwargs):
|
||||
self.nextchecktime = time.time() + self.timeout
|
||||
|
@ -33,7 +36,8 @@ class MQTTSensor(CBPiSensor):
|
|||
pass
|
||||
|
||||
async def message(self):
|
||||
self.cbpi.notify("MQTTSensor Timeout", "Sensor " + str(self.Topic) + " did not respond", NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
|
||||
target_timestring= datetime.fromtimestamp(self.lastdata)
|
||||
self.cbpi.notify("MQTTSensor Timeout", "Sensor '" + str(self.sensor.name) + "' did not respond. Last data received: "+target_timestring.strftime("%D %H:%M"), NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
|
||||
pass
|
||||
|
||||
async def on_message(self, message):
|
||||
|
@ -50,6 +54,7 @@ class MQTTSensor(CBPiSensor):
|
|||
if self.timeout !=0:
|
||||
self.nextchecktime = time.time() + self.timeout
|
||||
self.notificationsend = False
|
||||
self.lastdata=time.time()
|
||||
except Exception as e:
|
||||
logging.info("MQTT Sensor Error {}".format(e))
|
||||
|
||||
|
|
Loading…
Reference in a new issue