mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-21 21:13:01 +03:00
fix the model lookup KeyError for cameras added at runtime (#24026)
This commit is contained in:
committed by
Nicolas Mowen
parent
257a05a7e2
commit
46796fe9ef
@@ -9,6 +9,32 @@ from frigate.config.camera.updater import (
|
||||
CameraConfigUpdateSubscriber,
|
||||
)
|
||||
from frigate.const import SUB_CACHE_TAG
|
||||
from frigate.detectors.detector_config import SceneEnum
|
||||
|
||||
|
||||
def _build_scene_frigate_config(scene: str | None) -> FrigateConfig:
|
||||
detect = {"height": 1080, "width": 1920, "fps": 5}
|
||||
if scene is not None:
|
||||
detect["scene"] = scene
|
||||
return FrigateConfig(
|
||||
**{
|
||||
"mqtt": {"host": "mqtt"},
|
||||
"models": [
|
||||
{"devices": ["cpu"]},
|
||||
{"scene": "outdoor", "devices": ["openvino:CPU"]},
|
||||
],
|
||||
"cameras": {
|
||||
"front_door": {
|
||||
"ffmpeg": {
|
||||
"inputs": [
|
||||
{"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
|
||||
]
|
||||
},
|
||||
"detect": detect,
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def _build_camera_config(sub_enabled: bool) -> CameraConfig:
|
||||
@@ -86,6 +112,32 @@ class TestRecordUpdateRecreatesFfmpegCmds(unittest.TestCase):
|
||||
|
||||
assert not _has_sub_output(camera_config)
|
||||
|
||||
@patch("frigate.detectors.detector_config.load_labels")
|
||||
def test_removed_camera_readded_without_scene_gets_fresh_model(self, mock_labels):
|
||||
mock_labels.return_value = {}
|
||||
config = _build_scene_frigate_config("outdoor")
|
||||
subscriber = CameraConfigUpdateSubscriber(
|
||||
config, {}, [CameraConfigUpdateEnum.add, CameraConfigUpdateEnum.remove]
|
||||
)
|
||||
assert config.model_for_camera("front_door").scene == SceneEnum.outdoor
|
||||
|
||||
subscriber.subscriber.check_for_update.side_effect = [
|
||||
("config/cameras/front_door/remove", config.cameras["front_door"]),
|
||||
(None, None),
|
||||
]
|
||||
subscriber.check_for_updates()
|
||||
|
||||
# recreating the camera through the wizard leaves the scene unset,
|
||||
# so the removed camera's cached model must not carry over
|
||||
readded = _build_scene_frigate_config(None).cameras["front_door"]
|
||||
subscriber.subscriber.check_for_update.side_effect = [
|
||||
("config/cameras/front_door/add", readded),
|
||||
(None, None),
|
||||
]
|
||||
subscriber.check_for_updates()
|
||||
|
||||
assert config.model_for_camera("front_door").scene == SceneEnum.all
|
||||
|
||||
def test_unchanged_record_update_keeps_existing_cmds(self):
|
||||
camera_config = _build_camera_config(sub_enabled=False)
|
||||
subscriber = CameraConfigUpdateSubscriber(
|
||||
|
||||
Reference in New Issue
Block a user