From a22bf2b7119e7281057a505b53f44de7d9847d93 Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Thu, 19 Feb 2026 17:15:58 +0000 Subject: [PATCH] OpenCV camera: Fix startup behaviour loading camera from settings. --- .../things/camera/opencv.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/openflexure_microscope_server/things/camera/opencv.py b/src/openflexure_microscope_server/things/camera/opencv.py index d12d4f6b..36d4df3d 100644 --- a/src/openflexure_microscope_server/things/camera/opencv.py +++ b/src/openflexure_microscope_server/things/camera/opencv.py @@ -79,9 +79,16 @@ class OpenCVCamera(BaseCamera): @camera_name.setter def _set_camera_name(self, value: str) -> None: """Set the name of the camera.""" + if not self.cameras: + # Don't try to validate if cameras dict is empty, just set the value. + # As this is the startup behaviour. On __enter__ we check if the + # initial camera is valid and that at least 1 camera exists. + self._camera_name = value + # Return so we don't try to start the stream + return + if value not in self.cameras: - raise ValueError("{value} is not a valid camera name.") - self._camera_name = value + raise ValueError(f"{value} is not a valid camera name.") self._start_stream() def _start_stream(self) -> None: