-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option enabled for each camera in config #4162
Add option enabled for each camera in config #4162
Conversation
Also need to update configuration docs to reflect this new option |
Docs Update will follow if the reviews here are ok. I don't want to update the doc before the solution seems to be ok. |
Yes, docs and code updates should always be part of the same PR |
frigate/config.py
Outdated
@@ -530,6 +530,7 @@ class CameraUiConfig(FrigateBaseModel): | |||
|
|||
class CameraConfig(FrigateBaseModel): | |||
name: Optional[str] = Field(title="Camera name.", regex="^[a-zA-Z0-9_-]+$") | |||
enabled: Optional[bool] = Field(default=True, title="Enable camera.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enabled: Optional[bool] = Field(default=True, title="Enable camera.") | |
enabled: bool = Field(default=True, title="Enable camera.") |
You are using the Optional
qualifier which means the field is nullable, but it shouldn't be. This will always have a default value of True or a user set value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Simply misunderstood the Optional.
Code changes as requested and updated documentation for the new option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one small thing
frigate/config.py
Outdated
merged_config = deep_merge(camera.dict(exclude_unset=True), global_config) | ||
camera_config: CameraConfig = CameraConfig.parse_obj( | ||
{"name": name, **merged_config} | ||
) | ||
|
||
if not camera_config.enabled: | ||
config.cameras.pop(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested this, but won't this essentially just prevent the camera's config from being loaded at all? I thought the goal was to make it possible to have retain settings for a disabled camera that are different than the default values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you're right, I wasn't sure if that was supposed to be in this initial pass.
@banthungprong In that case we'd want to leave the config itself alone and not run the ffmpeg commands if the camera is disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we talk about 3 different requirements:
- static: Option in config, only used one time when starting the container (the original requirement for this PR). Camera settings aren't loaded in config.py.
- dynamic: Camera can be disabled or enabled while running frigate, so the config is changed in the UI. State of the camera will be saved "somewhere else" but not in the config. Settings are always available.
- "A bit of both": Option in config, when starting frigate the settings are loaded but the views (recording/events/live/rtmp etc) do not show a disabled camera. But additionaly features in the UI to enable/disable every camera. Setting are always available.
Is it enough to "not run the ffmpeg commands" or is more logic necessary in the different views when a camera isn't shown (example: Events View, dropdown Filter)? I will start digging and trying here today.
Close this pull request and make a new one based on requirement 2 or 3?
Or update this one and switch to the dynamic solution?
If starting to change parameters dynamically (enabled/disabled is only a first possibility) shouldn't there be a view for configurations showing each camera with a list of parameters that might be changed in the UI (resolution, framerate, etc.)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamic solution should come later, that's not what's being suggested.
This solution should still be static. The thing that's being discussed is we don't want the cameras config completely removed as we still want the retention settings to be applied. If a camera is disabled it just shouldn't be running, it should still show in the dropdowns and other places because you may still want to view those events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close this pull request and make a new one based on requirement 2 or 3?
Or update this one and switch to the dynamic solution?
I don't think there's a reason to close, but again we don't need the dynamic solution implemented. Just static solution that maintains camera settings in the config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I started looking already in app.py. And "some other places". I will try it and I hope it won't get too annoying if my commits aren't perfect...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not starting the process when the camera is disabled is working already.
Birdseye, Events, Debug all ok.
In Cameras: I hate the green image when no camera snapshot/stream is available...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Cameras: I hate the green image when no camera snapshot/stream is available...
That is on the list to improve in the 0.12.0 release, so I'd say leave it with the green screens for now as that is a separate PR which will address the green screen. Maybe having one message for cameras with errors and a different message for disabled cameras.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not start camera processors and capture processes when a camera is disabled. Working. Will commit in the morning. Too tired now.
Naming looks strange:
start_camera_processors vs start_capture_processes
whereas inside camera_process and capture_process looks ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some small stuff
docs/docs/configuration/index.md
Outdated
@@ -380,6 +380,10 @@ timestamp_style: | |||
cameras: | |||
# Required: name of the camera | |||
back: | |||
# Optional: Enable/Disable the camera (default: shown below). | |||
# If disabled: config is used but no live stream and no capture etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is incorrect for these (# is correct but doesn't need space after)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not understand this. Formatting is the same like other comment blocks with the Optional.
# in the same columns like the next line "enabled : True
and after # the same blanks like a few lines above
docs/docs/guides/getting_started.md
Outdated
@@ -62,6 +62,7 @@ detectors: | |||
|
|||
cameras: | |||
camera_1: # <------ Name the camera | |||
enabled: True # <----- Enable/disable camera |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it makes sense to put it here, this section is the minimal config and this isn't necessary
frigate/config.py
Outdated
@@ -816,7 +817,7 @@ def runtime_config(self) -> FrigateConfig: | |||
exclude_unset=True, | |||
) | |||
|
|||
for name, camera in config.cameras.items(): | |||
for name, camera in config.cameras.copy().items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need the copy here anymore
✅ Deploy Preview for frigate-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Commit comment length was limited (I just changed that in VS Code). So here a summary of the changes:
I didn't change the "wrong indentation" because I simply do not understand what might be wrong. |
docs/docs/configuration/index.md
Outdated
# Optional: Enable/Disable the camera (default: shown below). | ||
# If disabled: config is used but no live stream and no capture etc. | ||
# Events/Recordings are still viewable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Optional: Enable/Disable the camera (default: shown below). | |
# If disabled: config is used but no live stream and no capture etc. | |
# Events/Recordings are still viewable. | |
# Optional: Enable/Disable the camera (default: shown below). | |
# If disabled: config is used but no live stream and no capture etc. | |
# Events/Recordings are still viewable. |
this is what I mean, the start of the comment is indented too much
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this still needs to be addressed
docs/docs/configuration/index.md
Outdated
# Optional: Enable/Disable the camera (default: shown below). | ||
# If disabled: config is used but no live stream and no capture etc. | ||
# Events/Recordings are still viewable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this still needs to be addressed
A few lines above the indentation was used in the same way. It's not really consistent in the complete file. |
The ones that are indented start with |
* add option enabled for each camera in config * Simplified If-block and removed wrong Optional * Update Docs enabling/disabling camera in config * correct format for option * Disabling Camera for processes, no config changes * Describe effects of disabled cam in documentation * change if-logic, obsolete copy, info disabled cam * changed color to white, added top padding in disabled camera info * changed indentation
Is there also the possibility to disable a cam per mqtt? |
This works perfectly, thanks for this new option! |
Based on requirement and discussion in #4109:
Corrected 2 typos in config.py (propagate, generate)
Adding the if block resulted in 91 deletions and 96 additions after changing the indentation. The only real changes were:
in config.py in class CameraConfig
enabled: Optional[bool] = Field(default=True, title="Enable camera.")
in config.py in class FrigateConfig in runtime_config:
replace
for name, camera in config.cameras.items():
with
for name, camera in config.cameras.copy().items():
... generate camera_config ...
if camera_config.enabled:
... configurations ...
else: config.cameras.pop(name)
befor line
return config