add option enabled for each camera in config

This commit is contained in:
banthungprong 2022-10-25 07:29:04 +02:00
parent b4d4adb75b
commit 1fe6236f0c

View File

@ -530,6 +530,7 @@ class CameraUiConfig(FrigateBaseModel):
class CameraConfig(FrigateBaseModel): class CameraConfig(FrigateBaseModel):
name: Optional[str] = Field(title="Camera name.", regex="^[a-zA-Z0-9_-]+$") name: Optional[str] = Field(title="Camera name.", regex="^[a-zA-Z0-9_-]+$")
enabled: Optional[bool] = Field(default=True, title="Enable camera.")
ffmpeg: CameraFfmpegConfig = Field(title="FFmpeg configuration for the camera.") ffmpeg: CameraFfmpegConfig = Field(title="FFmpeg configuration for the camera.")
best_image_timeout: int = Field( best_image_timeout: int = Field(
default=60, default=60,
@ -799,7 +800,7 @@ class FrigateConfig(FrigateBaseModel):
if config.mqtt.password: if config.mqtt.password:
config.mqtt.password = config.mqtt.password.format(**FRIGATE_ENV_VARS) config.mqtt.password = config.mqtt.password.format(**FRIGATE_ENV_VARS)
# Global config to propegate down to camera level # Global config to propagate down to camera level
global_config = config.dict( global_config = config.dict(
include={ include={
"birdseye": ..., "birdseye": ...,
@ -816,12 +817,13 @@ class FrigateConfig(FrigateBaseModel):
exclude_unset=True, exclude_unset=True,
) )
for name, camera in config.cameras.items(): for name, camera in config.cameras.copy().items():
merged_config = deep_merge(camera.dict(exclude_unset=True), global_config) merged_config = deep_merge(camera.dict(exclude_unset=True), global_config)
camera_config: CameraConfig = CameraConfig.parse_obj( camera_config: CameraConfig = CameraConfig.parse_obj(
{"name": name, **merged_config} {"name": name, **merged_config}
) )
if camera_config.enabled:
# Default max_disappeared configuration # Default max_disappeared configuration
max_disappeared = camera_config.detect.fps * 5 max_disappeared = camera_config.detect.fps * 5
if camera_config.detect.max_disappeared is None: if camera_config.detect.max_disappeared is None:
@ -899,7 +901,9 @@ class FrigateConfig(FrigateBaseModel):
"The 'retain_days' config option has been DEPRECATED and will be removed in a future version. Please use the 'days' setting under 'retain'" "The 'retain_days' config option has been DEPRECATED and will be removed in a future version. Please use the 'days' setting under 'retain'"
) )
if camera_config.record.retain.days == 0: if camera_config.record.retain.days == 0:
camera_config.record.retain.days = camera_config.record.retain_days camera_config.record.retain.days = (
camera_config.record.retain_days
)
# warning if the higher level record mode is potentially more restrictive than the events # warning if the higher level record mode is potentially more restrictive than the events
rank_map = { rank_map = {
@ -915,10 +919,11 @@ class FrigateConfig(FrigateBaseModel):
logger.warning( logger.warning(
f"{name}: Recording retention is configured for {camera_config.record.retain.mode} and event retention is configured for {camera_config.record.events.retain.mode}. The more restrictive retention policy will be applied." f"{name}: Recording retention is configured for {camera_config.record.retain.mode} and event retention is configured for {camera_config.record.events.retain.mode}. The more restrictive retention policy will be applied."
) )
# generage the ffmpeg commands # generate the ffmpeg commands
camera_config.create_ffmpeg_cmds() camera_config.create_ffmpeg_cmds()
config.cameras[name] = camera_config config.cameras[name] = camera_config
else:
config.cameras.pop(name)
return config return config
@validator("cameras") @validator("cameras")