assign roles when single input and consolidate validation

This commit is contained in:
Blake Blackshear 2021-10-16 07:46:39 -05:00
parent f738275d21
commit 86a741b6e6
2 changed files with 21 additions and 24 deletions

View File

@ -86,29 +86,6 @@ class FrigateApp:
"frame_queue": mp.Queue(maxsize=2), "frame_queue": mp.Queue(maxsize=2),
} }
def check_config(self):
for name, camera in self.config.cameras.items():
assigned_roles = list(
set([r for i in camera.ffmpeg.inputs for r in i.roles])
)
if not camera.record.enabled and "record" in assigned_roles:
logger.warning(
f"Camera {name} has record assigned to an input, but record is not enabled."
)
elif camera.record.enabled and not "record" in assigned_roles:
logger.warning(
f"Camera {name} has record enabled, but record is not assigned to an input."
)
if not camera.rtmp.enabled and "rtmp" in assigned_roles:
logger.warning(
f"Camera {name} has rtmp assigned to an input, but rtmp is not enabled."
)
elif camera.rtmp.enabled and not "rtmp" in assigned_roles:
logger.warning(
f"Camera {name} has rtmp enabled, but rtmp is not assigned to an input."
)
def set_log_levels(self): def set_log_levels(self):
logging.getLogger().setLevel(self.config.logger.default.value.upper()) logging.getLogger().setLevel(self.config.logger.default.value.upper())
for log, level in self.config.logger.logs.items(): for log, level in self.config.logger.logs.items():
@ -338,7 +315,6 @@ class FrigateApp:
sys.exit(1) sys.exit(1)
self.set_environment_vars() self.set_environment_vars()
self.ensure_dirs() self.ensure_dirs()
self.check_config()
self.set_log_levels() self.set_log_levels()
self.init_queues() self.init_queues()
self.init_database() self.init_database()

View File

@ -504,6 +504,10 @@ class CameraConfig(FrigateBaseModel):
for idx, (name, z) in enumerate(config["zones"].items()) for idx, (name, z) in enumerate(config["zones"].items())
} }
# add roles to the input if there is only one
if len(config["ffmpeg"]["inputs"]) == 1:
config["ffmpeg"]["inputs"][0]["roles"] = ["record", "rtmp", "detect"]
super().__init__(**config) super().__init__(**config)
@property @property
@ -798,6 +802,23 @@ class FrigateConfig(FrigateBaseModel):
raise ValueError("Zones cannot share names with cameras") raise ValueError("Zones cannot share names with cameras")
return v return v
@validator("cameras")
def ensure_cameras_are_not_missing_roles(cls, v: Dict[str, CameraConfig]):
for name, camera in v.items():
assigned_roles = list(
set([r for i in camera.ffmpeg.inputs for r in i.roles])
)
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."
)
return v
@classmethod @classmethod
def parse_file(cls, config_file): def parse_file(cls, config_file):
with open(config_file) as f: with open(config_file) as f: