added rangewarning for testing (different color in dashboard -> dev version of ui required)

This commit is contained in:
avollkopf 2024-05-28 21:51:17 +02:00
parent f3a8fdf1a2
commit f594ed04a0
9 changed files with 63 additions and 25 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.4.1.a10"
__version__ = "4.4.1.a11"
__codename__ = "Yeast Starter"

View file

@ -79,7 +79,9 @@ class Sensor:
type: str = None
instance: str = None
datatype: DataType = DataType.VALUE
inrange: bool = True
temp_range: float = 0
def __str__(self):
return "name={} props={}, state={}".format(self.name, self.props, self.state)
def to_dict(self):

View file

@ -18,6 +18,10 @@ class CBPiSensor(CBPiBase, metaclass=ABCMeta):
self.state = False
self.running = False
self.datatype=DataType.VALUE
self.inrange = True
self.temprange = 0
self.kettle = None
self.fermenter = None
def init(self):
pass
@ -34,12 +38,34 @@ class CBPiSensor(CBPiBase, metaclass=ABCMeta):
def get_unit(self):
pass
def push_update(self, value, mqtt = True):
def checkrange(self, value):
# if Kettle and fermenter are selected, range check is deactivated
if self.kettle is not None and self.fermenter is not None:
return True
try:
self.cbpi.ws.send(dict(topic="sensorstate", id=self.id, value=value, datatype=self.datatype.value))
if self.kettle is not None:
target_temp=float(self.kettle.target_temp)
if self.fermenter is not None:
target_temp=float(self.fermenter.target_temp)
diff=abs(target_temp-value)
if diff>self.temprange:
return False
else:
return True
except Exception as e:
return True
def push_update(self, value, mqtt = True):
if self.temprange !=0:
self.inrange = self.checkrange(value)
else:
self.inrange = True
try:
self.cbpi.ws.send(dict(topic="sensorstate", id=self.id, value=value, datatype=self.datatype.value, inrange=self.inrange))
if mqtt:
self.cbpi.push_update("cbpi/sensordata/{}".format(self.id), dict(id=self.id, value=value, datatype=self.datatype.value), retain=True)
self.cbpi.push_update("cbpi/sensordata/{}".format(self.id), dict(id=self.id, value=value, datatype=self.datatype.value, inrange=self.inrange), retain=True)
# self.cbpi.push_update("cbpi/sensor/{}/udpate".format(self.id), dict(id=self.id, value=value), retain=True)
except:
logging.error("Failed to push sensor update for sensor {}".format(self.id))

View file

@ -12,10 +12,12 @@ cache = {}
@parameters([Property.Text(label="Key", configurable=True, description="Http Key"),
Property.Number(label="Timeout", configurable="True",unit="sec",description="Timeout in seconds to send notification (default:60 | deactivated: 0)"),
Property.Kettle(label="Kettle", description="Reduced logging if Kettle is inactive (only Kettle or Fermenter to be selected)"),
Property.Fermenter(label="Fermenter", description="Reduced logging in seconds if Fermenter is inactive (only Kettle or Fermenter to be selected)"),
Property.Number(label="ReducedLogging", configurable=True, description="Reduced logging frequency in seconds if selected Kettle or Fermenter is inactive (default: 60 sec | disabled: 0)")])
Property.Kettle(label="Kettle", description="Reduced logging if Kettle is inactive / range warning in dashboard (only Kettle or Fermenter to be selected)"),
Property.Fermenter(label="Fermenter", description="Reduced logging in seconds if Fermenter is inactive / range warning in dashboard (only Kettle or Fermenter to be selected)"),
Property.Number(label="ReducedLogging", configurable=True, description="Reduced logging frequency in seconds if selected Kettle or Fermenter is inactive (default: 60 sec | disabled: 0)"),
Property.Number(label="TempRange", configurable=True, unit="degree",
description="Temp range in degree between reading and target temp of fermenter/kettle. Larger difference shows different color in dashboard (default:0 | deactivated: 0)")
])
class HTTPSensor(CBPiSensor):
def __init__(self, cbpi, id, props):
super(HTTPSensor, self).__init__(cbpi, id, props)
@ -35,11 +37,12 @@ class HTTPSensor(CBPiSensor):
self.kettleid=self.props.get("Kettle", None)
self.fermenterid=self.props.get("Fermenter", None)
self.temprange=float(self.props.get("TempRange", 0))
self.reducedlogging = True if self.kettleid or self.fermenterid else False
if self.kettleid is not None and self.fermenterid is not None:
self.reducedlogging=False
self.cbpi.notify("HTTPSensor", "Sensor '" + str(self.sensor.name) + "' cant't have Fermenter and Kettle defined for reduced logging.", NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
self.cbpi.notify("HTTPSensor", "Sensor '" + str(self.sensor.name) + "' cant't have Fermenter and Kettle defined for reduced logging / range warning", NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
async def Confirm(self, **kwargs):
self.nextchecktime = time.time() + self.timeout

View file

@ -11,11 +11,13 @@ from datetime import datetime
@parameters([Property.Text(label="Topic", configurable=True, description="MQTT Topic"),
Property.Text(label="PayloadDictionary", configurable=True, default_value="",
description="Where to find msg in payload, leave blank for raw payload"),
Property.Kettle(label="Kettle", description="Reduced logging if Kettle is inactive (only Kettle or Fermenter to be selected)"),
Property.Fermenter(label="Fermenter", description="Reduced logging in seconds if Fermenter is inactive (only Kettle or Fermenter to be selected)"),
Property.Kettle(label="Kettle", description="Reduced logging if Kettle is inactive / range warning in dashboard (only Kettle or Fermenter to be selected)"),
Property.Fermenter(label="Fermenter", description="Reduced logging if Fermenter is inactive / range warning in dashboard (only Kettle or Fermenter to be selected)"),
Property.Number(label="ReducedLogging", configurable=True, description="Reduced logging frequency in seconds if selected Kettle or Fermenter is inactive (default:60 sec | 0 disabled)"),
Property.Number(label="Timeout", configurable=True, unit="sec",
description="Timeout in seconds to send notification (default:60 | deactivated: 0)")])
description="Timeout in seconds to send notification (default:60 | deactivated: 0)"),
Property.Number(label="TempRange", configurable=True, unit="degree",
description="Temp range in degree between reading and target temp of fermenter/kettle. Larger difference shows different color in dashboard (default:0 | deactivated: 0)")])
class MQTTSensor(CBPiSensor):
def __init__(self, cbpi, id, props):
@ -27,6 +29,7 @@ class MQTTSensor(CBPiSensor):
self.subscribed = self.cbpi.satellite.subscribe(self.Topic, self.on_message)
self.value: float = 999
self.timeout=int(self.props.get("Timeout", 60))
self.temprange=float(self.props.get("TempRange", 0))
self.starttime = time.time()
self.notificationsend = False
self.nextchecktime=self.starttime+self.timeout
@ -42,7 +45,7 @@ class MQTTSensor(CBPiSensor):
if self.kettleid is not None and self.fermenterid is not None:
self.reducedlogging=False
self.cbpi.notify("MQTTSensor", "Sensor '" + str(self.sensor.name) + "' cant't have Fermenter and Kettle defined for reduced logging.", NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
self.cbpi.notify("MQTTSensor", "Sensor '" + str(self.sensor.name) + "' cant't have Fermenter and Kettle defined for reduced logging / range warning.", NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
async def Confirm(self, **kwargs):
self.nextchecktime = time.time() + self.timeout

View file

@ -52,10 +52,13 @@ class ReadThread (threading.Thread):
@parameters([Property.Select(label="Sensor", options=getSensors()),
Property.Number(label="offset",configurable = True, default_value = 0, description="Sensor Offset (Default is 0)"),
Property.Select(label="Interval", options=[1,5,10,30,60], description="Interval in Seconds"),
Property.Kettle(label="Kettle", description="Reduced logging if Kettle is inactive (only Kettle or Fermenter to be selected)"),
Property.Fermenter(label="Fermenter", description="Reduced logging in seconds if Fermenter is inactive (only Kettle or Fermenter to be selected)"),
Property.Number(label="ReducedLogging", configurable=True, description="Reduced logging frequency in seconds if selected Kettle or Fermenter is inactive (default: 60 sec | disabled: 0)")
])
Property.Kettle(label="Kettle", description="Reduced logging if Kettle is inactive / range warning in dashboard(only Kettle or Fermenter to be selected)"),
Property.Fermenter(label="Fermenter", description="Reduced logging in seconds if Fermenter is inactive / range warning in dashboard (only Kettle or Fermenter to be selected)"),
Property.Number(label="ReducedLogging", configurable=True, description="Reduced logging frequency in seconds if selected Kettle or Fermenter is inactive (default: 60 sec | disabled: 0)"),
Property.Number(label="TempRange", configurable=True, unit="degree",
description="Temp range in degree between reading and target temp of fermenter/kettle. Larger difference shows different color in dashboard (default:0 | deactivated: 0)")
])
class OneWire(CBPiSensor):
def __init__(self, cbpi, id, props):
@ -72,6 +75,7 @@ class OneWire(CBPiSensor):
if self.reducedfrequency < 0:
self.reducedfrequency = 0
self.lastlog=0
self.temprange=float(self.props.get("TempRange", 0))
self.sensor=self.get_sensor(self.id)
self.kettleid=self.props.get("Kettle", None)
self.fermenterid=self.props.get("Fermenter", None)
@ -79,7 +83,7 @@ class OneWire(CBPiSensor):
if self.kettleid is not None and self.fermenterid is not None:
self.reducedlogging=False
self.cbpi.notify("OneWire Sensor", "Sensor '" + str(self.sensor.name) + "' cant't have Fermenter and Kettle defined for reduced logging.", NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
self.cbpi.notify("OneWire Sensor", "Sensor '" + str(self.sensor.name) + "' cant't have Fermenter and Kettle defined for reduced logging / range warning.", NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])
if (self.reducedfrequency != 0) and (self.interval >= self.reducedfrequency):
self.reducedlogging=False
self.cbpi.notify("OneWire Sensor", "Sensor '" + str(self.sensor.name) + "' has shorter or equal 'reduced logging' compared to regular interval.", NotificationType.WARNING, action=[NotificationAction("OK", self.Confirm)])

View file

@ -1,3 +1,3 @@
name: DummySensor
name: OneWireSensor
version: 4
active: true

View file

@ -10,7 +10,7 @@ aiojobs==1.2.1
aiosqlite==0.17.0
cryptography==42.0.5
pyopenssl==24.1.0
requests==2.31.0
requests==2.32.2
voluptuous==0.14.2
pyfiglet==1.0.2
pandas==2.2.2
@ -20,7 +20,7 @@ numpy==1.26.4
cbpi4gui
click==8.1.7
importlib_metadata==4.11.1
aiomqtt==2.0.1
aiomqtt==2.1.0
psutil==5.9.8
zipp>=0.5
colorama==0.4.6

View file

@ -50,13 +50,13 @@ setup(name='cbpi4',
"aiosqlite==0.17.0",
"cryptography==42.0.5",
"pyopenssl==24.1.0",
"requests==2.31.0",
"requests==2.32.2",
"voluptuous==0.14.2",
"pyfiglet==1.0.2",
'click==8.1.7',
'shortuuid==1.0.13',
'tabulate==0.9.0',
'aiomqtt==2.0.1',
'aiomqtt==2.1.0',
'inquirer==3.2.4',
'colorama==0.4.6',
'psutil==5.9.8',