Commit 2488deb7 authored by Peter-Bernd Otte's avatar Peter-Bernd Otte

improved debugging possibilities and exchanged remove->discard for set

parent 6565c9a6
......@@ -9,6 +9,7 @@ import yaml #pip3 install pyyaml
import os #for os.path.isfile
import logging, argparse
import sys
import traceback
logging.basicConfig(format="%(asctime)-15s %(levelname)-8s %(message)s")
logger = logging.getLogger("Actor")
......@@ -58,6 +59,7 @@ def on_disconnect(client, userdata, rc):
logger.warning("Unexpected MQTT disconnection. Will auto-reconnect")
def on_message(client, userdata, message):
try:
global mlast
t = datetime.now()
t = time.mktime(t.timetuple()) + t.microsecond / 1E6
......@@ -82,7 +84,9 @@ def on_message(client, userdata, message):
x.setV(j['v'],t=j['time'],reason="/set cmd called")
mlast[message.topic] = j
except:
traceback.print_exc()
quit(0)
client= paho.Client(args.mqtt_client_name)
......@@ -156,7 +160,6 @@ sleepTime = 1 if args.verbosity>0 else 0.025
while True:
for x in relaisList:
x.check()
time.sleep((1-time.time() % 1) * sleepTime) #every second, even if the processing before took longer
client.disconnect()
......
......@@ -86,12 +86,13 @@ class relais:
if self.debug: print(self.MQTTname,"Default Topic:", topic, "msg:", msg)
if msg['type'] in ('TFBHSB55', 'FBH63'): # motion sensors
self.timeLastStateConfirm = time.time()
if self.debug: print(self.MQTTname, "Check Motion Sensors")
if msg['v'] > 0:
self.lockingPIRs.add(topic)
self.lightdesire = rLightDesire.lockedDueToPIR
self.setV(1, reason="PIR motion")
else:
self.lockingPIRs.remove(topic)
self.lockingPIRs.discard(topic)
if len(self.lockingPIRs) == 0:
self.lightdesire = rLightDesire.stable
self.timeLastStateConfirm = time.time() # to avoid immediate switch off after last PIR
......@@ -110,7 +111,10 @@ class relais:
for x in self.prolongateStateTopics: # topics will only prolong the relais state
if topic == x:
if self.debug: print(self.MQTTname,"Prolong Topic:", topic, "msg:", msg)
if msg['type'] in ('TFBHSB55', 'FBH63'): # motion sensors
if self.v is None:
if self.debug: print(self.MQTTname,"no prolong operation possible, because self.v is not known yet")
else:
if msg['type'] in ('TFBHSB55', 'FBH63'): # motion sensors
if self.v > 0:
self.timeLastStateConfirm = time.time() # to avoid immediate switch off after last PIR
if msg['v'] > 0:
......@@ -119,13 +123,13 @@ class relais:
self.lightdesire = rLightDesire.lockedDueToPIR
self.publishCurrentStatus(reason="PIR motion prolong")
else:
self.lockingPIRs.remove(topic)
self.lockingPIRs.discard(topic)
if self.v > 0 and len(self.lockingPIRs) == 0:
self.lightdesire = rLightDesire.stable
self.publishCurrentStatus(reason="last PIR sees no motion")
if self.debug: print(self.MQTTname, "Prolong State Topic:", "len(self.lockingPIRs)", len(self.lockingPIRs),
"self.lockingPIRs", self.lockingPIRs)
else:
else:
print(self.MQTTname, "Error: Type not supported for prolongTopics.")
for x in self.toggleTopics: # topics do a toggle of the relais
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment