2021-06-29 00:27:27 +02:00
|
|
|
import queue
|
|
|
|
from fritzconnection.core.fritzmonitor import FritzMonitor
|
|
|
|
|
|
|
|
### Monitor the calls of a fritzbox continously ###
|
|
|
|
###################################################
|
|
|
|
|
2021-07-07 21:43:24 +02:00
|
|
|
def watch_disconnect(monitor, event_queue, func, tams, healthcheck_interval=10):
|
2021-06-29 00:27:27 +02:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
event = event_queue.get(timeout=healthcheck_interval)
|
|
|
|
except queue.Empty:
|
|
|
|
# check health:
|
|
|
|
if not monitor.is_alive:
|
|
|
|
raise OSError("Error: fritzmonitor connection failed")
|
|
|
|
else:
|
|
|
|
# do event processing here:
|
|
|
|
print(event)
|
|
|
|
if 'DISCONNECT' in event:
|
|
|
|
print("Anruf beendet. Jetzt den AB checken.\n")
|
2021-07-07 21:43:24 +02:00
|
|
|
func(tams)
|
2021-06-29 00:27:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-07 21:43:24 +02:00
|
|
|
def endedCall(func, tams, fritz_ip='192.168.1.1'):
|
2021-06-29 00:27:27 +02:00
|
|
|
"""
|
|
|
|
Call this to trigger a given function if a call is disconnected
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
# as a context manager FritzMonitor will shut down the monitor thread
|
|
|
|
with FritzMonitor(address=fritz_ip) as monitor:
|
|
|
|
event_queue = monitor.start()
|
2021-07-07 21:43:24 +02:00
|
|
|
watch_disconnect(monitor, event_queue, func, tams)
|
2021-06-29 00:27:27 +02:00
|
|
|
except (OSError, KeyboardInterrupt) as err:
|
|
|
|
print(err)
|
|
|
|
|
|
|
|
|