Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add eventstart and eventend actions. #2691

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions motioneye/handlers/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ 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}'
)
await self.event_start(camera_id)
return

elif action == 'eventend':
logging.debug(f'executing event_end action for camera with id {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:
Expand Down Expand Up @@ -123,3 +135,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({})
52 changes: 52 additions & 0 deletions motioneye/motionctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down