Skip to content

Commit 752f3f8

Browse files
committed
implement stream update while run setup active
1 parent 35af6b1 commit 752f3f8

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

api/src/opentrons/protocol_runner/run_orchestrator.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from opentrons_shared_data.labware.labware_definition import LabwareDefinition
1313
from opentrons_shared_data.errors import GeneralError
1414
from opentrons_shared_data.robot.types import RobotType
15-
from opentrons.system import camera
1615

1716
from . import protocol_runner, RunResult, JsonRunner, PythonAndLegacyRunner
1817
from ..hardware_control import HardwareControlAPI
@@ -195,13 +194,6 @@ async def run(
195194
run_time_param_values: Optional[PrimitiveRunTimeParamValuesType] = None,
196195
) -> RunResult:
197196
"""Start the run."""
198-
if self._camera_provider:
199-
await camera.update_live_stream_status(
200-
self.get_robot_type(),
201-
True,
202-
self._camera_provider,
203-
self._protocol_engine.state_view.camera.get_enablement_settings(),
204-
)
205197
if self._protocol_runner:
206198
return await self._protocol_runner.run(
207199
deck_configuration=deck_configuration,

api/src/opentrons/system/camera.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async def update_live_stream_status(
160160
raw_device = str(contents["SOURCE"])[1:-1]
161161
if not os.path.exists(raw_device):
162162
log.error(
163-
"Opentrons Live Stream cannot sample the camera. No video device found with device path: {raw_device}"
163+
f"Opentrons Live Stream cannot sample the camera. No video device found with device path: {raw_device}"
164164
)
165165
# Enable the stream
166166
status = "ON"

robot-server/robot_server/runs/router/camera_router.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
from server_utils.fastapi_utils.light_router import LightRouter
88

99
from opentrons.protocol_engine.resources.camera_provider import CameraSettings
10+
from opentrons.system import camera
1011

1112
from robot_server.errors.error_responses import ErrorBody
1213
from robot_server.service.json_api import (
1314
RequestModel,
1415
SimpleBody,
1516
PydanticResponse,
1617
)
18+
from robot_server.hardware import get_robot_type
19+
from opentrons_shared_data.robot.types import RobotType
20+
from robot_server.camera.fastapi_dependencies import (
21+
get_camera_provider,
22+
)
23+
from opentrons.protocol_engine.resources.camera_provider import CameraProvider
1724

1825
from ..run_models import Run
1926
from ..run_orchestrator_store import RunOrchestratorStore
@@ -48,13 +55,17 @@ async def add_camera_settings(
4855
RunOrchestratorStore, Depends(get_run_orchestrator_store)
4956
],
5057
run: Annotated[Run, Depends(get_run_data_from_url)],
58+
robot_type: Annotated[RobotType, Depends(get_robot_type)],
59+
camera_provider: Annotated[CameraProvider, Depends(get_camera_provider)],
5160
) -> PydanticResponse[SimpleBody[CameraEnable]]:
5261
"""Add unique camera settings to a run to be used in place of the global camera settings.
5362
5463
Args:
5564
request_body: New camera settings from request body.
5665
run_orchestrator_store: Engine storage interface.
5766
run: Run response data by ID from URL; ensures 404 if run not found.
67+
robot_type: Used to validate robot type for live stream service.
68+
camera_provider: Access to the camera settings and related services.
5869
"""
5970
if run.current is False:
6071
raise RunStopped(detail=f"Run {run.id} is not the current run").as_error(
@@ -78,6 +89,16 @@ async def add_camera_settings(
7889
)
7990
log.info(f'Added unique camera settings "{request_body.data}" to run "{run.id}".')
8091

92+
# Restart the stream with any the newest live stream settings
93+
await camera.update_live_stream_status(
94+
robot_type=robot_type,
95+
stream_status=response_data.liveStreamEnabled
96+
if response_data.cameraEnabled is True
97+
else False,
98+
camera_provider=camera_provider,
99+
override_settings=camera_settings,
100+
)
101+
81102
return await PydanticResponse.create(
82103
content=SimpleBody.model_construct(
83104
data=CameraEnable(

robot-server/robot_server/runs/run_data_manager.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from opentrons.protocol_engine.resources.file_provider import FileProvider
4141
from opentrons.protocol_engine.resources.camera_provider import CameraProvider
4242
from opentrons.protocol_engine.state.module_substates import FlexStackerSubState
43-
43+
from opentrons.system import camera
4444

4545
_INITIAL_ERROR_RECOVERY_RULES: list[ErrorRecoveryRule] = []
4646

@@ -283,6 +283,13 @@ async def create(
283283
run_id=run_id,
284284
)
285285

286+
await camera.update_live_stream_status(
287+
self._run_orchestrator_store._robot_type,
288+
True,
289+
camera_provider,
290+
state_summary.cameraSettings,
291+
)
292+
286293
return _build_run(
287294
run_resource=run_resource,
288295
state_summary=state_summary,

0 commit comments

Comments
 (0)