From 03647695739c24dc6624f94645c8d0434ab5d7bb Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 28 Mar 2023 07:00:21 +0200 Subject: [PATCH] fixed another bug in case of no logging during inactivity --- cbpi/extension/httpsensor/__init__.py | 52 ++++++++++++------------- cbpi/extension/mqtt_sensor/__init__.py | 53 +++++++++++++------------- cbpi/extension/onewire/__init__.py | 51 +++++++++++++------------ 3 files changed, 78 insertions(+), 78 deletions(-) diff --git a/cbpi/extension/httpsensor/__init__.py b/cbpi/extension/httpsensor/__init__.py index 74fc002..c37c11e 100644 --- a/cbpi/extension/httpsensor/__init__.py +++ b/cbpi/extension/httpsensor/__init__.py @@ -86,44 +86,42 @@ class HTTPSensor(CBPiSensor): await asyncio.sleep(1) async def logvalue(self): - 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() - else: - logging.info("Kettle Inactive") + 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 self.reducedfrequency != 0: 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 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 self.reducedfrequency != 0: 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 diff --git a/cbpi/extension/mqtt_sensor/__init__.py b/cbpi/extension/mqtt_sensor/__init__.py index b6c8d09..47114cf 100644 --- a/cbpi/extension/mqtt_sensor/__init__.py +++ b/cbpi/extension/mqtt_sensor/__init__.py @@ -79,38 +79,39 @@ class MQTTSensor(CBPiSensor): logging.error("MQTT Sensor Error {}".format(e)) async def logvalue(self): - 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() - else: - logging.info("MQTTSensor {} Kettle Inactive".format(self.sensor.name)) + 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 self.reducedfrequency != 0: 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 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 self.reducedfrequency != 0: if now >= self.lastlog + self.reducedfrequency: self.log_data(self.value) self.lastlog = time.time() diff --git a/cbpi/extension/onewire/__init__.py b/cbpi/extension/onewire/__init__.py index 663fb58..de78c78 100644 --- a/cbpi/extension/onewire/__init__.py +++ b/cbpi/extension/onewire/__init__.py @@ -123,37 +123,38 @@ class OneWire(CBPiSensor): await asyncio.sleep(self.interval) async def logvalue(self): - 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() - else: - logging.info("OneWire {} Kettle Inactive".format(self.sensor.name)) + 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 self.reducedfrequency != 0: 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 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 self.reducedfrequency != 0: if now >= self.lastlog + self.reducedfrequency: self.log_data(self.value) self.lastlog = time.time()