From 8b3845c07074b067b72b58e292723d36132623cd Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 21 Nov 2015 22:22:00 +0200 Subject: [PATCH] fixed thread_id_to_camera_id() --- motioneye/handlers.py | 7 +++++-- motioneye/motionctl.py | 16 ++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/motioneye/handlers.py b/motioneye/handlers.py index fa11e95..edfb390 100644 --- a/motioneye/handlers.py +++ b/motioneye/handlers.py @@ -1396,12 +1396,15 @@ class RelayEventHandler(BaseHandler): def post(self): event = self.get_argument('event') thread_id = int(self.get_argument('thread_id')) - logging.debug('recevied relayed event %(event)s for thread id %(id)s' % {'event': event, 'id': thread_id}) - + camera_id = motionctl.thread_id_to_camera_id(thread_id) if camera_id is None: logging.debug('ignoring event for unknown thread id %s' % thread_id) return self.finish_json() + + else: + logging.debug('recevied relayed event %(event)s for thread id %(id)s (camera id %(cid)s)' % { + 'event': event, 'id': thread_id, 'cid': camera_id}) camera_config = config.get_camera(camera_id) if not utils.local_motion_camera(camera_config): diff --git a/motioneye/motionctl.py b/motioneye/motionctl.py index 9c7116c..f3c6c7c 100644 --- a/motioneye/motionctl.py +++ b/motioneye/motionctl.py @@ -299,18 +299,10 @@ def camera_id_to_thread_id(camera_id): def thread_id_to_camera_id(thread_id): - # find the corresponding camera_id - # (which can be different from thread_id) - camera_ids = config.get_camera_ids() - tid = 0 - for cid in camera_ids: - camera_config = config.get_camera(cid) - if utils.local_motion_camera(camera_config): - tid += 1 - if tid == thread_id: - return cid - - return None + main_config = config.get_main() + threads = main_config.get('thread', '') + + return int(re.search('thread-(\d+).conf', threads[thread_id - 1]).group(1)) def _disable_initial_motion_detection(): -- 2.39.5