From eb02b7b0a59f80bee89863e5b7d17789f84fbee6 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Mon, 1 Sep 2014 20:01:15 +0300 Subject: [PATCH] motion detection status detection improvements --- src/motionctl.py | 15 +++++++++------ src/wsswitch.py | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/motionctl.py b/src/motionctl.py index bb244dc..c738ce5 100644 --- a/src/motionctl.py +++ b/src/motionctl.py @@ -191,15 +191,18 @@ def get_motion_detection(camera_id): url = 'http://127.0.0.1:7999/%(id)s/detection/status' % {'id': thread_id} - request = HTTPRequest(url, connect_timeout=2, request_timeout=2) + request = HTTPRequest(url, connect_timeout=5, request_timeout=5) http_client = HTTPClient() - response = http_client.fetch(request) - - if response.error: + try: + response = http_client.fetch(request) + if response.error: + raise response.error + + except Exception as e: logging.error('failed to get motion detection status for camera with id %(id)s: %(msg)s' % { 'id': camera_id, - 'msg': unicode(response.error)}) - + 'msg': unicode(e)}) + return None enabled = bool(response.body.lower().count('active')) diff --git a/src/wsswitch.py b/src/wsswitch.py index b0e72cd..15364ff 100644 --- a/src/wsswitch.py +++ b/src/wsswitch.py @@ -97,6 +97,10 @@ def _check_ws(): must_be_enabled = (now_during and working_schedule_type == 'during') or (not now_during and working_schedule_type == 'outside') currently_enabled = motionctl.get_motion_detection(camera_id) + if currently_enabled is None: # could not detect current status + logging.warn('skipping motion detection status update for camera with id %(id)s' % {'id': camera_id}) + continue + if currently_enabled and not must_be_enabled: logging.debug('must disable motion detection for camera with id %(id)s (%(what)s working schedule)' % { 'id': camera_id, -- 2.39.5