add detection enable to config

fixes #482
This commit is contained in:
Blake Blackshear 2021-01-15 21:53:40 -06:00
parent 97e8258288
commit 89e02b6956
2 changed files with 13 additions and 1 deletions

View File

@ -216,7 +216,9 @@ CAMERAS_SCHEMA = vol.Schema(vol.All(
}, },
'objects': OBJECTS_SCHEMA, 'objects': OBJECTS_SCHEMA,
vol.Optional('motion', default={}): MOTION_SCHEMA, vol.Optional('motion', default={}): MOTION_SCHEMA,
vol.Optional('detect', default={}): DETECT_SCHEMA vol.Optional('detect', default={}): DETECT_SCHEMA.extend({
vol.Optional('enabled', default=True): bool
})
} }
}, vol.Msg(ensure_zones_and_cameras_have_different_names, msg='Zones cannot share names with cameras')) }, vol.Msg(ensure_zones_and_cameras_have_different_names, msg='Zones cannot share names with cameras'))
) )
@ -737,14 +739,20 @@ class MotionConfig():
class DetectConfig(): class DetectConfig():
def __init__(self, global_config, config, camera_fps): def __init__(self, global_config, config, camera_fps):
self._enabled = config['enabled']
self._max_disappeared = config.get('max_disappeared', global_config.get('max_disappeared', camera_fps*2)) self._max_disappeared = config.get('max_disappeared', global_config.get('max_disappeared', camera_fps*2))
@property
def enabled(self):
return self._enabled
@property @property
def max_disappeared(self): def max_disappeared(self):
return self._max_disappeared return self._max_disappeared
def to_dict(self): def to_dict(self):
return { return {
'enabled': self.enabled,
'max_disappeared': self._max_disappeared, 'max_disappeared': self._max_disappeared,
} }

View File

@ -65,14 +65,18 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
camera_name = message.topic.split('/')[-3] camera_name = message.topic.split('/')[-3]
command = message.topic.split('/')[-1] command = message.topic.split('/')[-1]
detect_settings = config.cameras[camera_name].detect
if payload == 'ON': if payload == 'ON':
if not camera_metrics[camera_name]["detection_enabled"].value: if not camera_metrics[camera_name]["detection_enabled"].value:
logger.info(f"Turning on detection for {camera_name} via mqtt") logger.info(f"Turning on detection for {camera_name} via mqtt")
camera_metrics[camera_name]["detection_enabled"].value = True camera_metrics[camera_name]["detection_enabled"].value = True
detect_settings._enabled = True
elif payload == 'OFF': elif payload == 'OFF':
if camera_metrics[camera_name]["detection_enabled"].value: if camera_metrics[camera_name]["detection_enabled"].value:
logger.info(f"Turning off detection for {camera_name} via mqtt") logger.info(f"Turning off detection for {camera_name} via mqtt")
camera_metrics[camera_name]["detection_enabled"].value = False camera_metrics[camera_name]["detection_enabled"].value = False
detect_settings._enabled = False
else: else:
logger.warning(f"Received unsupported value at {message.topic}: {payload}") logger.warning(f"Received unsupported value at {message.topic}: {payload}")