From 117569830dd113562d545beb888a159bfc998997 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sun, 29 Nov 2020 19:00:46 -0600 Subject: [PATCH] ensure zones dont have the same name as a camera --- frigate/config.py | 11 +++++++++-- frigate/test/test_config.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/frigate/config.py b/frigate/config.py index b686cf080..a2bec0a90 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -144,7 +144,14 @@ CAMERA_FFMPEG_SCHEMA = vol.Schema( } ) -CAMERAS_SCHEMA = vol.Schema( +def ensure_zones_and_cameras_have_different_names(cameras): + zones = [zone for camera in cameras.values() for zone in camera['zones'].keys()] + for zone in zones: + if zone in cameras.keys(): + raise ValueError + return cameras + +CAMERAS_SCHEMA = vol.Schema(vol.All( { str: { vol.Required('ffmpeg'): CAMERA_FFMPEG_SCHEMA, @@ -177,7 +184,7 @@ CAMERAS_SCHEMA = vol.Schema( }, 'objects': OBJECTS_SCHEMA } - } + }, vol.Msg(ensure_zones_and_cameras_have_different_names, msg='Zones cannot share names with cameras')) ) FRIGATE_CONFIG_SCHEMA = vol.Schema( diff --git a/frigate/test/test_config.py b/frigate/test/test_config.py index c7b94bf5f..71b935540 100644 --- a/frigate/test/test_config.py +++ b/frigate/test/test_config.py @@ -246,6 +246,38 @@ class TestConfig(TestCase): } } self.assertRaises(vol.MultipleInvalid, lambda: FrigateConfig(config=config)) + + def test_zone_matching_camera_name_throws_error(self): + config = { + 'mqtt': { + 'host': 'mqtt' + }, + 'save_clips': { + 'retain': { + 'default': 20, + 'objects': { + 'person': 30 + } + } + }, + 'cameras': { + 'back': { + 'ffmpeg': { + 'inputs': [ + { 'path': 'rtsp://10.0.0.1:554/video', 'roles': ['detect'] } + ] + }, + 'height': 1080, + 'width': 1920, + 'zones': { + 'back': { + 'coordinates': '1,1,1,1,1,1' + } + } + } + } + } + self.assertRaises(vol.MultipleInvalid, lambda: FrigateConfig(config=config)) if __name__ == '__main__': main(verbosity=2)