From 828a82c4ad7e811b948892d588957889cf16a2bd Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Fri, 29 Aug 2025 15:33:06 +0200 Subject: [PATCH] Move get_dynamic_camera_stream_settings to prefs --- homeassistant/components/camera/__init__.py | 8 ++++++-- homeassistant/components/camera/helper.py | 12 +----------- homeassistant/components/camera/prefs.py | 11 ++++++++++- homeassistant/components/go2rtc/__init__.py | 2 +- .../camera/{test_helper.py => test_prefs.py} | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) rename tests/components/camera/{test_helper.py => test_prefs.py} (97%) diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index aae892610ba..b54cca05c22 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -79,9 +79,13 @@ from .const import ( CameraState, StreamType, ) -from .helper import get_camera_from_entity_id, get_dynamic_camera_stream_settings +from .helper import get_camera_from_entity_id from .img_util import scale_jpeg_camera_image -from .prefs import CameraPreferences, DynamicStreamSettings # noqa: F401 +from .prefs import ( + CameraPreferences, + DynamicStreamSettings, # noqa: F401 + get_dynamic_camera_stream_settings, +) from .webrtc import ( DATA_ICE_SERVERS, CameraWebRTCProvider, diff --git a/homeassistant/components/camera/helper.py b/homeassistant/components/camera/helper.py index 8fd6d6cf20c..5e84b18dda8 100644 --- a/homeassistant/components/camera/helper.py +++ b/homeassistant/components/camera/helper.py @@ -7,11 +7,10 @@ from typing import TYPE_CHECKING from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from .const import DATA_CAMERA_PREFS, DATA_COMPONENT +from .const import DATA_COMPONENT if TYPE_CHECKING: from . import Camera - from .prefs import DynamicStreamSettings def get_camera_from_entity_id(hass: HomeAssistant, entity_id: str) -> Camera: @@ -27,12 +26,3 @@ def get_camera_from_entity_id(hass: HomeAssistant, entity_id: str) -> Camera: raise HomeAssistantError("Camera is off") return camera - - -async def get_dynamic_camera_stream_settings( - hass: HomeAssistant, entity_id: str -) -> DynamicStreamSettings: - """Get dynamic stream settings for a camera entity.""" - if DATA_CAMERA_PREFS not in hass.data: - raise HomeAssistantError("Camera integration not set up") - return await hass.data[DATA_CAMERA_PREFS].get_dynamic_stream_settings(entity_id) diff --git a/homeassistant/components/camera/prefs.py b/homeassistant/components/camera/prefs.py index 2eccaf500e1..ceeb050b899 100644 --- a/homeassistant/components/camera/prefs.py +++ b/homeassistant/components/camera/prefs.py @@ -13,7 +13,7 @@ from homeassistant.helpers import entity_registry as er from homeassistant.helpers.storage import Store from homeassistant.helpers.typing import UNDEFINED, UndefinedType -from .const import DOMAIN, PREF_ORIENTATION, PREF_PRELOAD_STREAM +from .const import DATA_CAMERA_PREFS, DOMAIN, PREF_ORIENTATION, PREF_PRELOAD_STREAM STORAGE_KEY: Final = DOMAIN STORAGE_VERSION: Final = 1 @@ -106,3 +106,12 @@ class CameraPreferences: ) self._dynamic_stream_settings_by_entity_id[entity_id] = settings return settings + + +async def get_dynamic_camera_stream_settings( + hass: HomeAssistant, entity_id: str +) -> DynamicStreamSettings: + """Get dynamic stream settings for a camera entity.""" + if DATA_CAMERA_PREFS not in hass.data: + raise HomeAssistantError("Camera integration not set up") + return await hass.data[DATA_CAMERA_PREFS].get_dynamic_stream_settings(entity_id) diff --git a/homeassistant/components/go2rtc/__init__.py b/homeassistant/components/go2rtc/__init__.py index eb277ff49f4..3bfce841ce5 100644 --- a/homeassistant/components/go2rtc/__init__.py +++ b/homeassistant/components/go2rtc/__init__.py @@ -31,7 +31,7 @@ from homeassistant.components.camera import ( WebRTCSendMessage, async_register_webrtc_provider, ) -from homeassistant.components.camera.helper import get_dynamic_camera_stream_settings +from homeassistant.components.camera.prefs import get_dynamic_camera_stream_settings from homeassistant.components.default_config import DOMAIN as DEFAULT_CONFIG_DOMAIN from homeassistant.components.stream import Orientation from homeassistant.config_entries import SOURCE_SYSTEM, ConfigEntry diff --git a/tests/components/camera/test_helper.py b/tests/components/camera/test_prefs.py similarity index 97% rename from tests/components/camera/test_helper.py rename to tests/components/camera/test_prefs.py index 5fb9f914a81..e4b3e67f15d 100644 --- a/tests/components/camera/test_helper.py +++ b/tests/components/camera/test_prefs.py @@ -3,10 +3,10 @@ import pytest from homeassistant.components.camera.const import DATA_CAMERA_PREFS -from homeassistant.components.camera.helper import get_dynamic_camera_stream_settings from homeassistant.components.camera.prefs import ( CameraPreferences, DynamicStreamSettings, + get_dynamic_camera_stream_settings, ) from homeassistant.components.stream import Orientation from homeassistant.core import HomeAssistant