From d2c3c7e78219c3e2e1e18a94872e9e41a7b4f962 Mon Sep 17 00:00:00 2001 From: clavay Date: Wed, 25 Jan 2023 17:00:24 +0100 Subject: [PATCH 1/4] add eventstart and eventend actions. --- motioneye/handlers/action.py | 18 +++++++++++++ motioneye/motionctl.py | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/motioneye/handlers/action.py b/motioneye/handlers/action.py index b494d0742..227b88513 100644 --- a/motioneye/handlers/action.py +++ b/motioneye/handlers/action.py @@ -66,6 +66,16 @@ async def post(self, camera_id, action): ) return self.record_stop(camera_id) + elif action == 'eventstart': + logging.debug('executing event_start action for camera with id %s' % camera_id) + await self.event_start(camera_id) + return + + elif action == 'eventend': + logging.debug('executing event_end action for camera with id %s' % camera_id) + await self.event_end(camera_id) + return + action_commands = config.get_action_commands(local_config) command = action_commands.get(action) if not command: @@ -123,3 +133,11 @@ def record_start(self, camera_id): def record_stop(self, camera_id): return self.finish_json({}) + + async def event_start(self, camera_id): + await motionctl.start_event(camera_id) + return self.finish_json({}) + + async def event_end(self, camera_id): + await motionctl.end_event(camera_id) + return self.finish_json({}) diff --git a/motioneye/motionctl.py b/motioneye/motionctl.py index 272e487af..d9b392949 100644 --- a/motioneye/motionctl.py +++ b/motioneye/motionctl.py @@ -301,6 +301,58 @@ async def take_snapshot(camera_id): logging.debug(f'successfully took snapshot for camera with id {camera_id}') +async def start_event(camera_id): + motion_camera_id = camera_id_to_motion_camera_id(camera_id) + if motion_camera_id is None: + return logging.error( + f'could not find motion camera id for camera with id {camera_id}' + ) + + logging.debug(f'starting event for camera with id {camera_id}') + + url = f'http://127.0.0.1:{settings.MOTION_CONTROL_PORT}/{motion_camera_id}/action/eventstart' + + request = HTTPRequest( + url, + connect_timeout=_MOTION_CONTROL_TIMEOUT, + request_timeout=_MOTION_CONTROL_TIMEOUT, + ) + resp = await AsyncHTTPClient().fetch(request) + if resp.error: + logging.error( + f'failed to start event for camera with id {camera_id}: {utils.pretty_http_error(resp)}' + ) + + else: + logging.debug(f'successfully start event for camera with id {camera_id}') + + +async def end_event(camera_id): + motion_camera_id = camera_id_to_motion_camera_id(camera_id) + if motion_camera_id is None: + return logging.error( + f'could not find motion camera id for camera with id {camera_id}' + ) + + logging.debug(f'ending event for camera with id {camera_id}') + + url = f'http://127.0.0.1:{settings.MOTION_CONTROL_PORT}/{motion_camera_id}/action/eventend' + + request = HTTPRequest( + url, + connect_timeout=_MOTION_CONTROL_TIMEOUT, + request_timeout=_MOTION_CONTROL_TIMEOUT, + ) + resp = await AsyncHTTPClient().fetch(request) + if resp.error: + logging.error( + f'failed to end event for camera with id {camera_id}: {utils.pretty_http_error(resp)}' + ) + + else: + logging.debug(f'successfully end event for camera with id {camera_id}') + + def is_motion_detected(camera_id): return _motion_detected.get(camera_id, False) From 4b9ef7c7ab64cbde702bd63d3e5989068aba2d99 Mon Sep 17 00:00:00 2001 From: clavay <38041007+clavay@users.noreply.github.com> Date: Thu, 26 Jan 2023 10:14:42 +0100 Subject: [PATCH 2/4] Update motioneye/handlers/action.py Co-authored-by: MichaIng --- motioneye/handlers/action.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/motioneye/handlers/action.py b/motioneye/handlers/action.py index 227b88513..83a76bb2c 100644 --- a/motioneye/handlers/action.py +++ b/motioneye/handlers/action.py @@ -72,7 +72,7 @@ async def post(self, camera_id, action): return elif action == 'eventend': - logging.debug('executing event_end action for camera with id %s' % camera_id) + logging.debug(f'executing event_end action for camera with id {camera_id}') await self.event_end(camera_id) return From edacc1738b7e6bfea73b753ba1c1ba36d44579e4 Mon Sep 17 00:00:00 2001 From: clavay <38041007+clavay@users.noreply.github.com> Date: Thu, 26 Jan 2023 10:14:53 +0100 Subject: [PATCH 3/4] Update motioneye/handlers/action.py Co-authored-by: MichaIng --- motioneye/handlers/action.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/motioneye/handlers/action.py b/motioneye/handlers/action.py index 83a76bb2c..2aa87e0da 100644 --- a/motioneye/handlers/action.py +++ b/motioneye/handlers/action.py @@ -67,7 +67,7 @@ async def post(self, camera_id, action): return self.record_stop(camera_id) elif action == 'eventstart': - logging.debug('executing event_start action for camera with id %s' % camera_id) + logging.debug(f'executing event_start action for camera with id {camera_id}') await self.event_start(camera_id) return From 565c2751f890dd36ce4764826d8b7b9173857ac5 Mon Sep 17 00:00:00 2001 From: clavay <38041007+clavay@users.noreply.github.com> Date: Sat, 28 Jan 2023 21:23:41 +0100 Subject: [PATCH 4/4] Update motioneye/handlers/action.py Co-authored-by: MichaIng --- motioneye/handlers/action.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/motioneye/handlers/action.py b/motioneye/handlers/action.py index 2aa87e0da..1687002be 100644 --- a/motioneye/handlers/action.py +++ b/motioneye/handlers/action.py @@ -67,7 +67,9 @@ async def post(self, camera_id, action): return self.record_stop(camera_id) elif action == 'eventstart': - logging.debug(f'executing event_start action for camera with id {camera_id}') + logging.debug( + f'executing event_start action for camera with id {camera_id}' + ) await self.event_start(camera_id) return