From b33753f334b96faa1cfd6f66ab44507d11d8a610 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Mon, 8 Feb 2021 21:21:14 -0800 Subject: [PATCH] Move camera timeouts to constants (#46262) Addresses feedback from pr #45431. Also removes an redundant `create_stream` timeout. --- homeassistant/components/camera/__init__.py | 9 +++++---- homeassistant/components/camera/const.py | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index cbc98edf19b..ba61f155473 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -46,6 +46,8 @@ from homeassistant.helpers.network import get_url from homeassistant.loader import bind_hass from .const import ( + CAMERA_IMAGE_TIMEOUT, + CAMERA_STREAM_SOURCE_TIMEOUT, CONF_DURATION, CONF_LOOKBACK, DATA_CAMERA_PREFS, @@ -359,7 +361,7 @@ class Camera(Entity): """Create a Stream for stream_source.""" # There is at most one stream (a decode worker) per camera if not self.stream: - async with async_timeout.timeout(10): + async with async_timeout.timeout(CAMERA_STREAM_SOURCE_TIMEOUT): source = await self.stream_source() if not source: return None @@ -506,7 +508,7 @@ class CameraImageView(CameraView): async def handle(self, request: web.Request, camera: Camera) -> web.Response: """Serve camera image.""" with suppress(asyncio.CancelledError, asyncio.TimeoutError): - async with async_timeout.timeout(10): + async with async_timeout.timeout(CAMERA_IMAGE_TIMEOUT): image = await camera.async_camera_image() if image: @@ -717,8 +719,7 @@ async def _async_stream_endpoint_url(hass, camera, fmt): async def async_handle_record_service(camera, call): """Handle stream recording service calls.""" - async with async_timeout.timeout(10): - stream = await camera.create_stream() + stream = await camera.create_stream() if not stream: raise HomeAssistantError(f"{camera.entity_id} does not support record service") diff --git a/homeassistant/components/camera/const.py b/homeassistant/components/camera/const.py index 615e54b0eca..7218b19f8fe 100644 --- a/homeassistant/components/camera/const.py +++ b/homeassistant/components/camera/const.py @@ -9,3 +9,6 @@ SERVICE_RECORD = "record" CONF_LOOKBACK = "lookback" CONF_DURATION = "duration" + +CAMERA_STREAM_SOURCE_TIMEOUT = 10 +CAMERA_IMAGE_TIMEOUT = 10