def on_motion_detection_status(camera_id, must_be_enabled, working_schedule_type, enabled=None, error=None): if error: # could not detect current status return logging.warn( 'skipping motion detection status update for camera with id %(id)s: %(error)s' % { 'id': camera_id, 'error': error }) if 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, 'what': working_schedule_type }) motionctl.set_motion_detection(camera_id, False) elif not enabled and must_be_enabled: logging.debug( 'must enable motion detection for camera with id %(id)s (%(what)s working schedule)' % { 'id': camera_id, 'what': working_schedule_type }) motionctl.set_motion_detection(camera_id, True)
def _set_all_motion_detection(enable): import motionctl def on_set_config_response(error=None): if error is None: logging.debug("Saving motion detection failed") else: logging.debug("Motion detection saved successfully") def on_get_config_response(remote_ui_config=None, error=None): remote_ui_config["motion_detection"] = enable remote.set_config(local_config, remote_ui_config, on_set_config_response) for camera_id in config.get_camera_ids(): camera_config = config.get_camera(camera_id) if not utils.is_local_motion_camera(camera_config): local_config = config.get_camera(camera_id) remote.get_config(local_config, on_get_config_response) logging.debug( 'motion detection %s by config for remote camera with id %s' % (str(enable), camera_id)) elif not camera_config['@motion_detection']: logging.debug( 'motion detection %s by config for local camera with id %s' % (str(enable), camera_id)) motionctl.set_motion_detection(camera_id, enable) else: logging.error("Couldn't categorize camera with id %s" % camera_id)
def _check_ws(): # schedule the next call ioloop = tornado.ioloop.IOLoop.instance() ioloop.add_timeout(datetime.timedelta(seconds=10), _check_ws) if not motionctl.running(): return now = datetime.datetime.now() for camera_id in config.get_camera_ids(): camera_config = config.get_camera(camera_id) if not utils.local_motion_camera(camera_config): continue working_schedule = camera_config.get('@working_schedule') motion_detection = camera_config.get('@motion_detection') working_schedule_type = camera_config.get( '@working_schedule_type') or 'outside' if not working_schedule: # working schedule disabled, motion detection left untouched continue if not motion_detection: # motion detection explicitly disabled continue now_during = _during_working_schedule(now, working_schedule) 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, 'what': working_schedule_type }) motionctl.set_motion_detection(camera_id, False) elif not currently_enabled and must_be_enabled: logging.debug( 'must enable motion detection for camera with id %(id)s (%(what)s working schedule)' % { 'id': camera_id, 'what': working_schedule_type }) motionctl.set_motion_detection(camera_id, True)
def on_motion_detection_status(camera_id, must_be_enabled, working_schedule_type, enabled=None, error=None): if error: # could not detect current status return logging.warn('skipping motion detection status update for camera with id %(id)s' % {'id': camera_id}) if 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, 'what': working_schedule_type}) motionctl.set_motion_detection(camera_id, False) elif not enabled and must_be_enabled: logging.debug('must enable motion detection for camera with id %(id)s (%(what)s working schedule)' % { 'id': camera_id, 'what': working_schedule_type}) motionctl.set_motion_detection(camera_id, True)
def _check_ws(): # schedule the next call ioloop = tornado.ioloop.IOLoop.instance() ioloop.add_timeout(datetime.timedelta(seconds=10), _check_ws) if not motionctl.running(): return now = datetime.datetime.now() for camera_id in config.get_camera_ids(): camera_config = config.get_camera(camera_id) if not utils.local_motion_camera(camera_config): continue working_schedule = camera_config.get('@working_schedule') motion_detection = camera_config.get('@motion_detection') working_schedule_type = camera_config.get('@working_schedule_type') or 'outside' if not working_schedule: # working schedule disabled, motion detection left untouched continue if not motion_detection: # motion detection explicitly disabled continue now_during = _during_working_schedule(now, working_schedule) 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, 'what': working_schedule_type}) motionctl.set_motion_detection(camera_id, False) elif not currently_enabled and must_be_enabled: logging.debug('must enable motion detection for camera with id %(id)s (%(what)s working schedule)' % { 'id': camera_id, 'what': working_schedule_type}) motionctl.set_motion_detection(camera_id, True)