diff --git a/frigate/config.py b/frigate/config.py index d464bb9702..6ff88dc00d 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -792,22 +792,21 @@ def runtime_config(self) -> FrigateConfig: **camera_config.motion.dict(exclude_unset=True), ) - config.cameras[name] = camera_config - # check runtime config - for name, camera in config.cameras.items(): - assigned_roles = list( - set([r for i in camera.ffmpeg.inputs for r in i.roles]) + assigned_roles = list( + set([r for i in camera_config.ffmpeg.inputs for r in i.roles]) + ) + if camera_config.record.enabled and not "record" in assigned_roles: + raise ValueError( + f"Camera {name} has record enabled, but record is not assigned to an input." ) - if camera.record.enabled and not "record" in assigned_roles: - raise ValueError( - f"Camera {name} has record enabled, but record is not assigned to an input." - ) - if camera.rtmp.enabled and not "rtmp" in assigned_roles: - raise ValueError( - f"Camera {name} has rtmp enabled, but rtmp is not assigned to an input." - ) + if camera_config.rtmp.enabled and not "rtmp" in assigned_roles: + raise ValueError( + f"Camera {name} has rtmp enabled, but rtmp is not assigned to an input." + ) + + config.cameras[name] = camera_config return config diff --git a/frigate/test/test_config.py b/frigate/test/test_config.py index 92b30d542b..d1f2416e6b 100644 --- a/frigate/test/test_config.py +++ b/frigate/test/test_config.py @@ -752,6 +752,56 @@ def test_fails_on_missing_role(self): frigate_config = FrigateConfig(**config) self.assertRaises(ValueError, lambda: frigate_config.runtime_config) + def test_works_on_missing_role_multiple_cams(self): + + config = { + "mqtt": {"host": "mqtt"}, + "rtmp": {"enabled": False}, + "cameras": { + "back": { + "ffmpeg": { + "inputs": [ + { + "path": "rtsp://10.0.0.1:554/video", + "roles": ["detect"], + }, + { + "path": "rtsp://10.0.0.1:554/video2", + "roles": ["record"], + }, + ] + }, + "detect": { + "height": 1080, + "width": 1920, + "fps": 5, + }, + }, + "cam2": { + "ffmpeg": { + "inputs": [ + { + "path": "rtsp://10.0.0.1:554/video", + "roles": ["detect"], + }, + { + "path": "rtsp://10.0.0.1:554/video2", + "roles": ["record"], + }, + ] + }, + "detect": { + "height": 1080, + "width": 1920, + "fps": 5, + }, + }, + }, + } + + frigate_config = FrigateConfig(**config) + runtime_config = frigate_config.runtime_config + def test_global_detect(self): config = {