mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Deprecate deprecated camera constants (#106095)
This commit is contained in:
parent
3404bd4de5
commit
20ba764d92
@ -51,6 +51,11 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
|
||||
PLATFORM_SCHEMA,
|
||||
PLATFORM_SCHEMA_BASE,
|
||||
)
|
||||
from homeassistant.helpers.deprecation import (
|
||||
DeprecatedConstantEnum,
|
||||
check_if_deprecated_constant,
|
||||
dir_with_deprecated_constants,
|
||||
)
|
||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
@ -60,6 +65,8 @@ from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
from .const import ( # noqa: F401
|
||||
_DEPRECATED_STREAM_TYPE_HLS,
|
||||
_DEPRECATED_STREAM_TYPE_WEB_RTC,
|
||||
CAMERA_IMAGE_TIMEOUT,
|
||||
CAMERA_STREAM_SOURCE_TIMEOUT,
|
||||
CONF_DURATION,
|
||||
@ -70,8 +77,6 @@ from .const import ( # noqa: F401
|
||||
PREF_ORIENTATION,
|
||||
PREF_PRELOAD_STREAM,
|
||||
SERVICE_RECORD,
|
||||
STREAM_TYPE_HLS,
|
||||
STREAM_TYPE_WEB_RTC,
|
||||
StreamType,
|
||||
)
|
||||
from .img_util import scale_jpeg_camera_image
|
||||
@ -105,8 +110,16 @@ class CameraEntityFeature(IntFlag):
|
||||
|
||||
# These SUPPORT_* constants are deprecated as of Home Assistant 2022.5.
|
||||
# Pleease use the CameraEntityFeature enum instead.
|
||||
SUPPORT_ON_OFF: Final = 1
|
||||
SUPPORT_STREAM: Final = 2
|
||||
_DEPRECATED_SUPPORT_ON_OFF: Final = DeprecatedConstantEnum(
|
||||
CameraEntityFeature.ON_OFF, "2025.1"
|
||||
)
|
||||
_DEPRECATED_SUPPORT_STREAM: Final = DeprecatedConstantEnum(
|
||||
CameraEntityFeature.STREAM, "2025.1"
|
||||
)
|
||||
|
||||
# Both can be removed if no deprecated constant are in this module anymore
|
||||
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
|
||||
__dir__ = partial(dir_with_deprecated_constants, module_globals=globals())
|
||||
|
||||
RTSP_PREFIXES = {"rtsp://", "rtsps://", "rtmp://"}
|
||||
|
||||
@ -215,7 +228,7 @@ async def _async_get_stream_image(
|
||||
height: int | None = None,
|
||||
wait_for_next_keyframe: bool = False,
|
||||
) -> bytes | None:
|
||||
if not camera.stream and camera.supported_features & SUPPORT_STREAM:
|
||||
if not camera.stream and camera.supported_features & CameraEntityFeature.STREAM:
|
||||
camera.stream = await camera.async_create_stream()
|
||||
if camera.stream:
|
||||
return await camera.stream.async_get_image(
|
||||
|
@ -1,7 +1,14 @@
|
||||
"""Constants for Camera component."""
|
||||
from enum import StrEnum
|
||||
from functools import partial
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.helpers.deprecation import (
|
||||
DeprecatedConstantEnum,
|
||||
check_if_deprecated_constant,
|
||||
dir_with_deprecated_constants,
|
||||
)
|
||||
|
||||
DOMAIN: Final = "camera"
|
||||
|
||||
DATA_CAMERA_PREFS: Final = "camera_prefs"
|
||||
@ -36,5 +43,10 @@ class StreamType(StrEnum):
|
||||
|
||||
# These constants are deprecated as of Home Assistant 2022.5
|
||||
# Please use the StreamType enum instead.
|
||||
STREAM_TYPE_HLS = "hls"
|
||||
STREAM_TYPE_WEB_RTC = "web_rtc"
|
||||
_DEPRECATED_STREAM_TYPE_HLS = DeprecatedConstantEnum(StreamType.HLS, "2025.1")
|
||||
_DEPRECATED_STREAM_TYPE_WEB_RTC = DeprecatedConstantEnum(StreamType.WEB_RTC, "2025.1")
|
||||
|
||||
|
||||
# Both can be removed if no deprecated constant are in this module anymore
|
||||
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
|
||||
__dir__ = partial(dir_with_deprecated_constants, module_globals=globals())
|
||||
|
@ -2,6 +2,7 @@
|
||||
import asyncio
|
||||
from http import HTTPStatus
|
||||
import io
|
||||
from types import ModuleType
|
||||
from unittest.mock import AsyncMock, Mock, PropertyMock, mock_open, patch
|
||||
|
||||
import pytest
|
||||
@ -26,6 +27,7 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import EMPTY_8_6_JPEG, WEBRTC_ANSWER, mock_turbo_jpeg
|
||||
|
||||
from tests.common import import_and_test_deprecated_constant_enum
|
||||
from tests.typing import ClientSessionGenerator, WebSocketGenerator
|
||||
|
||||
STREAM_SOURCE = "rtsp://127.0.0.1/stream"
|
||||
@ -939,7 +941,7 @@ async def test_use_stream_for_stills(
|
||||
# Test when the integration does not provide a stream_source should fail
|
||||
with patch(
|
||||
"homeassistant.components.demo.camera.DemoCamera.supported_features",
|
||||
return_value=camera.SUPPORT_STREAM,
|
||||
return_value=camera.CameraEntityFeature.STREAM,
|
||||
):
|
||||
resp = await client.get("/api/camera_proxy/camera.demo_camera")
|
||||
await hass.async_block_till_done()
|
||||
@ -953,7 +955,7 @@ async def test_use_stream_for_stills(
|
||||
"homeassistant.components.camera.create_stream"
|
||||
) as mock_create_stream, patch(
|
||||
"homeassistant.components.demo.camera.DemoCamera.supported_features",
|
||||
return_value=camera.SUPPORT_STREAM,
|
||||
return_value=camera.CameraEntityFeature.STREAM,
|
||||
), patch(
|
||||
"homeassistant.components.demo.camera.DemoCamera.use_stream_for_stills",
|
||||
return_value=True,
|
||||
@ -971,3 +973,36 @@ async def test_use_stream_for_stills(
|
||||
mock_stream.async_get_image.assert_called_once()
|
||||
assert resp.status == HTTPStatus.OK
|
||||
assert await resp.read() == b"stream_keyframe_image"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"enum",
|
||||
list(camera.const.StreamType),
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"module",
|
||||
[camera, camera.const],
|
||||
)
|
||||
def test_deprecated_stream_type_constants(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
enum: camera.const.StreamType,
|
||||
module: ModuleType,
|
||||
) -> None:
|
||||
"""Test deprecated stream type constants."""
|
||||
import_and_test_deprecated_constant_enum(
|
||||
caplog, module, enum, "STREAM_TYPE_", "2025.1"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"entity_feature",
|
||||
list(camera.CameraEntityFeature),
|
||||
)
|
||||
def test_deprecated_support_constants(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
entity_feature: camera.CameraEntityFeature,
|
||||
) -> None:
|
||||
"""Test deprecated support constants."""
|
||||
import_and_test_deprecated_constant_enum(
|
||||
caplog, camera, entity_feature, "SUPPORT_", "2025.1"
|
||||
)
|
||||
|
@ -53,7 +53,7 @@ async def mock_camera(hass) -> AsyncGenerator[None, None]:
|
||||
return_value=STREAM_SOURCE,
|
||||
), patch(
|
||||
"homeassistant.components.camera.Camera.supported_features",
|
||||
return_value=camera.SUPPORT_STREAM,
|
||||
return_value=camera.CameraEntityFeature.STREAM,
|
||||
):
|
||||
yield
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user