From c4ceb4759a1c45f80a96c47c988b5e8ddec1d3de Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Fri, 9 May 2025 13:08:34 +0200 Subject: [PATCH] Remove deprecated camera frontend_stream_type (#144539) --- homeassistant/components/camera/__init__.py | 51 ------------------- .../axis/snapshots/test_camera.ambr | 2 - tests/components/camera/test_init.py | 25 --------- tests/components/nest/test_camera.py | 2 - .../netatmo/snapshots/test_camera.ambr | 2 - .../ring/snapshots/test_camera.ambr | 3 -- .../tplink/snapshots/test_camera.ambr | 1 - tests/components/unifiprotect/test_camera.py | 10 ++-- .../custom_components/test/camera.py | 41 --------------- 9 files changed, 7 insertions(+), 130 deletions(-) delete mode 100644 tests/testing_config/custom_components/test/camera.py diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index aa5d766c874..ba80864b769 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -61,7 +61,6 @@ from homeassistant.helpers.deprecation import ( from homeassistant.helpers.entity import Entity, EntityDescription from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.event import async_track_time_interval -from homeassistant.helpers.frame import ReportBehavior, report_usage from homeassistant.helpers.network import get_url from homeassistant.helpers.template import Template from homeassistant.helpers.typing import ConfigType, VolDictType @@ -436,7 +435,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: CACHED_PROPERTIES_WITH_ATTR_ = { "brand", "frame_interval", - "frontend_stream_type", "is_on", "is_recording", "is_streaming", @@ -456,8 +454,6 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): # Entity Properties _attr_brand: str | None = None _attr_frame_interval: float = MIN_STREAM_INTERVAL - # Deprecated in 2024.12. Remove in 2025.6 - _attr_frontend_stream_type: StreamType | None _attr_is_on: bool = True _attr_is_recording: bool = False _attr_is_streaming: bool = False @@ -488,16 +484,6 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): type(self).async_handle_async_webrtc_offer != Camera.async_handle_async_webrtc_offer ) - self._deprecate_attr_frontend_stream_type_logged = False - if type(self).frontend_stream_type != Camera.frontend_stream_type: - report_usage( - ( - f"is overwriting the 'frontend_stream_type' property in the {type(self).__name__} class," - " which is deprecated and will be removed in Home Assistant 2025.6, " - ), - core_integration_behavior=ReportBehavior.ERROR, - exclude_integrations={DOMAIN}, - ) @cached_property def entity_picture(self) -> str: @@ -559,40 +545,6 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): """Return the interval between frames of the mjpeg stream.""" return self._attr_frame_interval - @property - def frontend_stream_type(self) -> StreamType | None: - """Return the type of stream supported by this camera. - - A camera may have a single stream type which is used to inform the - frontend which camera attributes and player to use. The default type - is to use HLS, and components can override to change the type. - """ - # Deprecated in 2024.12. Remove in 2025.6 - # Use the camera_capabilities instead - if hasattr(self, "_attr_frontend_stream_type"): - if not self._deprecate_attr_frontend_stream_type_logged: - report_usage( - ( - f"is setting the '_attr_frontend_stream_type' attribute in the {type(self).__name__} class," - " which is deprecated and will be removed in Home Assistant 2025.6, " - ), - core_integration_behavior=ReportBehavior.ERROR, - exclude_integrations={DOMAIN}, - ) - - self._deprecate_attr_frontend_stream_type_logged = True - return self._attr_frontend_stream_type - if CameraEntityFeature.STREAM not in self.supported_features_compat: - return None - if ( - self._webrtc_provider - or self._legacy_webrtc_provider - or self._supports_native_sync_webrtc - or self._supports_native_async_webrtc - ): - return StreamType.WEB_RTC - return StreamType.HLS - @property def available(self) -> bool: """Return True if entity is available.""" @@ -797,9 +749,6 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): if motion_detection_enabled := self.motion_detection_enabled: attrs["motion_detection"] = motion_detection_enabled - if frontend_stream_type := self.frontend_stream_type: - attrs["frontend_stream_type"] = frontend_stream_type - return attrs @callback diff --git a/tests/components/axis/snapshots/test_camera.ambr b/tests/components/axis/snapshots/test_camera.ambr index 1e70e2a799f..d323a209dc8 100644 --- a/tests/components/axis/snapshots/test_camera.ambr +++ b/tests/components/axis/snapshots/test_camera.ambr @@ -39,7 +39,6 @@ 'access_token': '1', 'entity_picture': '/api/camera_proxy/camera.home?token=1', 'friendly_name': 'home', - 'frontend_stream_type': , 'supported_features': , }), 'context': , @@ -90,7 +89,6 @@ 'access_token': '1', 'entity_picture': '/api/camera_proxy/camera.home?token=1', 'friendly_name': 'home', - 'frontend_stream_type': , 'supported_features': , }), 'context': , diff --git a/tests/components/camera/test_init.py b/tests/components/camera/test_init.py index 7fd469fa51a..7fd5cd0855f 100644 --- a/tests/components/camera/test_init.py +++ b/tests/components/camera/test_init.py @@ -27,7 +27,6 @@ from homeassistant.components.camera.helper import get_camera_from_entity_id from homeassistant.components.websocket_api import TYPE_RESULT from homeassistant.const import ( ATTR_ENTITY_ID, - CONF_PLATFORM, EVENT_HOMEASSISTANT_STARTED, STATE_UNAVAILABLE, ) @@ -1036,27 +1035,3 @@ async def test_camera_capabilities_changing_native_support( await hass.async_block_till_done() await _test_capabilities(hass, hass_ws_client, cam.entity_id, set(), set()) - - -@pytest.mark.usefixtures("enable_custom_integrations") -async def test_deprecated_frontend_stream_type_logs( - hass: HomeAssistant, - caplog: pytest.LogCaptureFixture, -) -> None: - """Test using (_attr_)frontend_stream_type will log.""" - assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}}) - await hass.async_block_till_done() - - for entity_id in ( - "camera.property_frontend_stream_type", - "camera.attr_frontend_stream_type", - ): - camera_obj = get_camera_from_entity_id(hass, entity_id) - assert camera_obj.frontend_stream_type == StreamType.WEB_RTC - - assert ( - "Detected that custom integration 'test' is overwriting the 'frontend_stream_type' property in the PropertyFrontendStreamTypeCamera class, which is deprecated and will be removed in Home Assistant 2025.6," - ) in caplog.text - assert ( - "Detected that custom integration 'test' is setting the '_attr_frontend_stream_type' attribute in the AttrFrontendStreamTypeCamera class, which is deprecated and will be removed in Home Assistant 2025.6," - ) in caplog.text diff --git a/tests/components/nest/test_camera.py b/tests/components/nest/test_camera.py index 3e7dbd3f223..c0579c99a62 100644 --- a/tests/components/nest/test_camera.py +++ b/tests/components/nest/test_camera.py @@ -826,7 +826,6 @@ async def test_camera_multiple_streams( assert cam is not None assert cam.state == CameraState.STREAMING # Prefer WebRTC over RTSP/HLS - assert cam.attributes["frontend_stream_type"] == StreamType.WEB_RTC client = await hass_ws_client(hass) assert await async_frontend_stream_types(client, "camera.my_camera") == [ StreamType.WEB_RTC @@ -905,7 +904,6 @@ async def test_webrtc_refresh_expired_stream( cam = hass.states.get("camera.my_camera") assert cam is not None assert cam.state == CameraState.STREAMING - assert cam.attributes["frontend_stream_type"] == StreamType.WEB_RTC client = await hass_ws_client(hass) assert await async_frontend_stream_types(client, "camera.my_camera") == [ StreamType.WEB_RTC diff --git a/tests/components/netatmo/snapshots/test_camera.ambr b/tests/components/netatmo/snapshots/test_camera.ambr index 9bd10ed9b5f..7f38e261768 100644 --- a/tests/components/netatmo/snapshots/test_camera.ambr +++ b/tests/components/netatmo/snapshots/test_camera.ambr @@ -42,7 +42,6 @@ 'brand': 'Netatmo', 'entity_picture': '/api/camera_proxy/camera.front?token=1caab5c3b3', 'friendly_name': 'Front', - 'frontend_stream_type': , 'id': '12:34:56:10:b9:0e', 'is_local': False, 'light_state': None, @@ -104,7 +103,6 @@ 'brand': 'Netatmo', 'entity_picture': '/api/camera_proxy/camera.hall?token=1caab5c3b3', 'friendly_name': 'Hall', - 'frontend_stream_type': , 'id': '12:34:56:00:f1:62', 'is_local': True, 'light_state': None, diff --git a/tests/components/ring/snapshots/test_camera.ambr b/tests/components/ring/snapshots/test_camera.ambr index 8c3b8a083b0..0e5efd68753 100644 --- a/tests/components/ring/snapshots/test_camera.ambr +++ b/tests/components/ring/snapshots/test_camera.ambr @@ -94,7 +94,6 @@ 'attribution': 'Data provided by Ring.com', 'entity_picture': '/api/camera_proxy/camera.front_door_live_view?token=1caab5c3b3', 'friendly_name': 'Front Door Live view', - 'frontend_stream_type': , 'last_video_id': None, 'supported_features': , 'video_url': None, @@ -201,7 +200,6 @@ 'attribution': 'Data provided by Ring.com', 'entity_picture': '/api/camera_proxy/camera.front_live_view?token=1caab5c3b3', 'friendly_name': 'Front Live view', - 'frontend_stream_type': , 'last_video_id': None, 'supported_features': , 'video_url': None, @@ -309,7 +307,6 @@ 'attribution': 'Data provided by Ring.com', 'entity_picture': '/api/camera_proxy/camera.internal_live_view?token=1caab5c3b3', 'friendly_name': 'Internal Live view', - 'frontend_stream_type': , 'last_video_id': None, 'supported_features': , 'video_url': None, diff --git a/tests/components/tplink/snapshots/test_camera.ambr b/tests/components/tplink/snapshots/test_camera.ambr index e037c2c9e40..67749b30d1a 100644 --- a/tests/components/tplink/snapshots/test_camera.ambr +++ b/tests/components/tplink/snapshots/test_camera.ambr @@ -39,7 +39,6 @@ 'access_token': '1caab5c3b3', 'entity_picture': '/api/camera_proxy/camera.my_camera_live_view?token=1caab5c3b3', 'friendly_name': 'my_camera Live view', - 'frontend_stream_type': , 'supported_features': , }), 'context': , diff --git a/tests/components/unifiprotect/test_camera.py b/tests/components/unifiprotect/test_camera.py index 975e93edf09..34a1d064547 100644 --- a/tests/components/unifiprotect/test_camera.py +++ b/tests/components/unifiprotect/test_camera.py @@ -12,6 +12,7 @@ from uiprotect.websocket import WebsocketState from webrtc_models import RTCIceCandidateInit from homeassistant.components.camera import ( + CameraCapabilities, CameraEntityFeature, CameraState, CameraWebRTCProvider, @@ -21,6 +22,7 @@ from homeassistant.components.camera import ( async_get_stream_source, async_register_webrtc_provider, ) +from homeassistant.components.camera.helper import get_camera_from_entity_id from homeassistant.components.unifiprotect.const import ( ATTR_BITRATE, ATTR_CHANNEL_ID, @@ -345,9 +347,11 @@ async def test_webrtc_support( camera_high_only.channels[2].is_rtsp_enabled = False await init_entry(hass, ufp, [camera_high_only]) entity_id = validate_default_camera_entity(hass, camera_high_only, 0) - state = hass.states.get(entity_id) - assert state - assert StreamType.WEB_RTC in state.attributes["frontend_stream_type"] + assert hass.states.get(entity_id) + camera_obj = get_camera_from_entity_id(hass, entity_id) + assert camera_obj.camera_capabilities == CameraCapabilities( + {StreamType.HLS, StreamType.WEB_RTC} + ) async def test_adopt( diff --git a/tests/testing_config/custom_components/test/camera.py b/tests/testing_config/custom_components/test/camera.py deleted file mode 100644 index b2aa1bbc53b..00000000000 --- a/tests/testing_config/custom_components/test/camera.py +++ /dev/null @@ -1,41 +0,0 @@ -"""Provide a mock remote platform. - -Call init before using it in your tests to ensure clean test data. -""" - -from homeassistant.components.camera import Camera, CameraEntityFeature, StreamType -from homeassistant.core import HomeAssistant -from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType - - -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities_callback: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Return mock entities.""" - async_add_entities_callback( - [AttrFrontendStreamTypeCamera(), PropertyFrontendStreamTypeCamera()] - ) - - -class AttrFrontendStreamTypeCamera(Camera): - """attr frontend stream type Camera.""" - - _attr_name = "attr frontend stream type" - _attr_supported_features: CameraEntityFeature = CameraEntityFeature.STREAM - _attr_frontend_stream_type: StreamType = StreamType.WEB_RTC - - -class PropertyFrontendStreamTypeCamera(Camera): - """property frontend stream type Camera.""" - - _attr_name = "property frontend stream type" - _attr_supported_features: CameraEntityFeature = CameraEntityFeature.STREAM - - @property - def frontend_stream_type(self) -> StreamType | None: - """Return the stream type of the camera.""" - return StreamType.WEB_RTC