From b56f9d839f4744e3dd7d9cdd8c158909088e3b85 Mon Sep 17 00:00:00 2001 From: Michael Clemens Date: Tue, 8 Dec 2020 12:19:16 +0100 Subject: [PATCH] code cleanup --- pyBMNotify.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pyBMNotify.py b/pyBMNotify.py index dc41b6d..c5f3dc6 100644 --- a/pyBMNotify.py +++ b/pyBMNotify.py @@ -49,7 +49,7 @@ def on_mqtt(*args): callsign = call["SourceCall"] start_time = call["Start"] stop_time = call["Stop"] - msg = "" + notify = False now = int(time.time()) # check if callsign is monitored, the transmission has already been finished # and the person was inactive for n seconds @@ -63,10 +63,11 @@ def on_mqtt(*args): last_TG_activity[tg] = now # remember the transmission time stamp of this particular DMR user last_OM_activity[callsign] = now - msg = construct_message(call) + #msg = construct_message(call) + notify = True # Continue if the talkgroup is monitored, the transmission has been finished and there was no activity # during the last n seconds in this talkgroup - elif tg in cfg.talkgroups and stop_time > 0 and callsign not in cfg.noisy_calls: + elif tg in cfg.talkgroups and stop_time > 0:# and callsign not in cfg.noisy_calls: if tg not in last_TG_activity: last_TG_activity[tg] = 9999999 inactivity = now - last_TG_activity[tg] @@ -75,16 +76,18 @@ def on_mqtt(*args): # only proceed if the key down has been long enough if duration >= cfg.min_duration: if tg not in last_TG_activity or inactivity >= cfg.min_silence: - msg = construct_message(call) + #msg = construct_message(call) + notify = True elif cfg.verbose: print("ignored activity in TG " + str(tg) + " from " + callsign + ": last action " + str(inactivity) + " seconds ago.") last_TG_activity[tg] = now if cfg.verbose and callsign in cfg.noisy_calls: print("ignored noisy ham " + callsign) # finally write the message to the console and send a push notification - if msg != "": - print(construct_message(call)) - push_message(construct_message(call)) + if notify: + msg = construct_message(call) + print(msg) + push_message(msg) socket = SocketIO('https://api.brandmeister.network/lh') socket.on('connect', on_connect)