added sensor disabling with fermenter/kettle inactivity

This commit is contained in:
avollkopf 2023-03-27 20:19:37 +02:00
parent 5a2b0a8bd0
commit 187426eb4a
6 changed files with 108 additions and 97 deletions

3
.gitignore vendored
View file

@ -4,8 +4,7 @@ build
dist
.idea
*.log
cbpi.egg-info
cbpi4.egg-info
/cbpi4.egg-info
log
venv
cbpi/extension/ui

View file

@ -1,3 +1,3 @@
__version__ = "4.1.7.rc1"
__version__ = "4.1.7.rc2"
__codename__ = "Groundhog Day"

View file

@ -14,7 +14,7 @@ cache = {}
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 is 60 sec)")])
Property.Number(label="ReducedLogging", configurable=True, description="Reduced logging frequency in seconds if selected Kettle or Fermenter is inactive (default: 60 sec | disabled: 0)")])
class HTTPSensor(CBPiSensor):
def __init__(self, cbpi, id, props):
@ -30,6 +30,8 @@ class HTTPSensor(CBPiSensor):
self.lastlog=0
self.reducedfrequency=int(self.props.get("ReducedLogging", 60))
if self.reducedfrequency < 0:
self.reducedfrequency = 0
self.kettleid=self.props.get("Kettle", None)
self.fermenterid=self.props.get("Fermenter", None)
@ -84,40 +86,44 @@ class HTTPSensor(CBPiSensor):
await asyncio.sleep(1)
async def logvalue(self):
now=time.time()
if self.kettle is not None:
try:
kettlestatus=self.kettle.instance.state
except:
kettlestatus=False
if kettlestatus:
self.log_data(self.value)
logging.info("Kettle Active")
self.lastlog = time.time()
else:
logging.info("Kettle Inactive")
if now >= self.lastlog + self.reducedfrequency:
if self.reducedfrequency != 0:
now=time.time()
if self.kettle is not None:
try:
kettlestatus=self.kettle.instance.state
except:
kettlestatus=False
if kettlestatus:
self.log_data(self.value)
logging.info("Kettle Active")
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
else:
logging.info("Kettle Inactive")
if now >= self.lastlog + self.reducedfrequency:
self.log_data(self.value)
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
if self.fermenter is not None:
try:
fermenterstatus=self.fermenter.instance.state
except:
fermenterstatus=False
if fermenterstatus:
self.log_data(self.value)
logging.info("Fermenter Active")
self.lastlog = time.time()
else:
logging.info("Fermenter Inactive")
if now >= self.lastlog + self.reducedfrequency:
if self.fermenter is not None:
try:
fermenterstatus=self.fermenter.instance.state
except:
fermenterstatus=False
if fermenterstatus:
self.log_data(self.value)
logging.info("Fermenter Active")
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
else:
logging.info("Fermenter Inactive")
if now >= self.lastlog + self.reducedfrequency:
self.log_data(self.value)
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
else:
logging.warning("No logging")
pass
def get_state(self):
# return the current state of the sensor

View file

@ -13,7 +13,7 @@ from datetime import datetime
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.Number(label="ReducedLogging", configurable=True, description="Reduced logging frequency in seconds if selected Kettle or Fermenter is inactive (default is 60 sec)"),
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)")])
class MQTTSensor(CBPiSensor):
@ -34,6 +34,8 @@ class MQTTSensor(CBPiSensor):
self.lastlog=0
self.sensor=self.get_sensor(self.id)
self.reducedfrequency=int(self.props.get("ReducedLogging", 60))
if self.reducedfrequency < 0:
self.reducedfrequency = 0
self.kettleid=self.props.get("Kettle", None)
self.fermenterid=self.props.get("Fermenter", None)
self.reducedlogging = True if self.kettleid or self.fermenterid else False
@ -77,42 +79,43 @@ class MQTTSensor(CBPiSensor):
logging.error("MQTT Sensor Error {}".format(e))
async def logvalue(self):
self.kettle = self.get_kettle(self.kettleid) if self.kettleid is not None else None
self.fermenter = self.get_fermenter(self.fermenterid) if self.fermenterid is not None else None
now=time.time()
if self.kettle is not None:
try:
kettlestatus=self.kettle.instance.state
except:
kettlestatus=False
if kettlestatus:
self.log_data(self.value)
logging.info("MQTTSensor {} Kettle Active".format(self.sensor.name))
self.lastlog = time.time()
else:
logging.info("MQTTSensor {} Kettle Inactive".format(self.sensor.name))
if now >= self.lastlog + self.reducedfrequency:
if self.reducedfrequency == 0:
self.kettle = self.get_kettle(self.kettleid) if self.kettleid is not None else None
self.fermenter = self.get_fermenter(self.fermenterid) if self.fermenterid is not None else None
now=time.time()
if self.kettle is not None:
try:
kettlestatus=self.kettle.instance.state
except:
kettlestatus=False
if kettlestatus:
self.log_data(self.value)
logging.info("MQTTSensor {} Kettle Active".format(self.sensor.name))
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
else:
logging.info("MQTTSensor {} Kettle Inactive".format(self.sensor.name))
if now >= self.lastlog + self.reducedfrequency:
self.log_data(self.value)
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
if self.fermenter is not None:
try:
fermenterstatus=self.fermenter.instance.state
except:
fermenterstatus=False
if fermenterstatus:
self.log_data(self.value)
logging.info("MQTTSensor {} Fermenter Active".format(self.sensor.name))
self.lastlog = time.time()
else:
logging.info("MQTTSensor {} Fermenter Inactive".format(self.sensor.name))
if now >= self.lastlog + self.reducedfrequency:
if self.fermenter is not None:
try:
fermenterstatus=self.fermenter.instance.state
except:
fermenterstatus=False
if fermenterstatus:
self.log_data(self.value)
logging.info("MQTTSensor {} Fermenter Active".format(self.sensor.name))
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
else:
logging.info("MQTTSensor {} Fermenter Inactive".format(self.sensor.name))
if now >= self.lastlog + self.reducedfrequency:
self.log_data(self.value)
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
async def run(self):
while self.running:

View file

@ -54,7 +54,7 @@ class ReadThread (threading.Thread):
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 is 60 sec)")
Property.Number(label="ReducedLogging", configurable=True, description="Reduced logging frequency in seconds if selected Kettle or Fermenter is inactive (default: 60 sec | disabled: 0)")
])
class OneWire(CBPiSensor):
@ -69,6 +69,8 @@ class OneWire(CBPiSensor):
self.offset = float(self.props.get("offset",0))
self.reducedfrequency=float(self.props.get("ReducedLogging", 60))
if self.reducedfrequency < 0:
self.reducedfrequency = 0
self.lastlog=0
self.sensor=self.get_sensor(self.id)
self.kettleid=self.props.get("Kettle", None)
@ -121,41 +123,42 @@ class OneWire(CBPiSensor):
await asyncio.sleep(self.interval)
async def logvalue(self):
now=time.time()
logging.info("OneWire {} logging subroutine".format(self.sensor.name))
if self.kettle is not None:
try:
kettlestatus=self.kettle.instance.state
except:
kettlestatus=False
if kettlestatus:
self.log_data(self.value)
logging.info("OneWire {} Kettle Active".format(self.sensor.name))
self.lastlog = time.time()
else:
logging.info("OneWire {} Kettle Inactive".format(self.sensor.name))
if now >= self.lastlog + self.reducedfrequency:
if self.reducedfrequency == 0:
now=time.time()
logging.info("OneWire {} logging subroutine".format(self.sensor.name))
if self.kettle is not None:
try:
kettlestatus=self.kettle.instance.state
except:
kettlestatus=False
if kettlestatus:
self.log_data(self.value)
logging.info("OneWire {} Kettle Active".format(self.sensor.name))
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
else:
logging.info("OneWire {} Kettle Inactive".format(self.sensor.name))
if now >= self.lastlog + self.reducedfrequency:
self.log_data(self.value)
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
if self.fermenter is not None:
try:
fermenterstatus=self.fermenter.instance.state
except:
fermenterstatus=False
if fermenterstatus:
self.log_data(self.value)
logging.info("OneWire {} Fermenter Active".format(self.sensor.name))
self.lastlog = time.time()
else:
logging.info("OneWire {} Fermenter Inactive".format(self.sensor.name))
if now >= self.lastlog + self.reducedfrequency:
if self.fermenter is not None:
try:
fermenterstatus=self.fermenter.instance.state
except:
fermenterstatus=False
if fermenterstatus:
self.log_data(self.value)
logging.info("OneWire {} Fermenter Active".format(self.sensor.name))
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
else:
logging.info("OneWire {} Fermenter Inactive".format(self.sensor.name))
if now >= self.lastlog + self.reducedfrequency:
self.log_data(self.value)
self.lastlog = time.time()
logging.info("Logged with reduced freqency")
pass
def get_state(self):

View file

@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: cbpi4
Version: 4.1.7a4
Version: 4.1.7rc1
Summary: CraftBeerPi4 Brewing Software
Home-page: http://web.craftbeerpi.com
Author: Manuel Fritsch / Alexander Vollkopf