Move get_dynamic_camera_stream_settings to prefs

This commit is contained in:
Robert Resch
2025-08-29 15:33:06 +02:00
parent 679ff29992
commit 828a82c4ad
5 changed files with 19 additions and 16 deletions

View File

@@ -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,

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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