From aa855e31c8b11bce68e90d9bf78d2640487e7d0e Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Mon, 28 Oct 2024 15:47:22 +0100 Subject: [PATCH] Convert async_get_webrtc_client_configuration to a callback (#129329) --- homeassistant/components/camera/__init__.py | 8 +++++--- homeassistant/components/camera/webrtc.py | 2 +- homeassistant/components/nest/camera.py | 5 +++-- tests/components/camera/test_webrtc.py | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index 70394fc3c0e..b0fba8a120c 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -803,14 +803,16 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): return await fn(self.hass, self) - async def _async_get_webrtc_client_configuration(self) -> WebRTCClientConfiguration: + @callback + def _async_get_webrtc_client_configuration(self) -> WebRTCClientConfiguration: """Return the WebRTC client configuration adjustable per integration.""" return WebRTCClientConfiguration() @final - async def async_get_webrtc_client_configuration(self) -> WebRTCClientConfiguration: + @callback + def async_get_webrtc_client_configuration(self) -> WebRTCClientConfiguration: """Return the WebRTC client configuration and extend it with the registered ice servers.""" - config = await self._async_get_webrtc_client_configuration() + config = self._async_get_webrtc_client_configuration() ice_servers = [ server diff --git a/homeassistant/components/camera/webrtc.py b/homeassistant/components/camera/webrtc.py index cd79e0cefad..28729ce55bf 100644 --- a/homeassistant/components/camera/webrtc.py +++ b/homeassistant/components/camera/webrtc.py @@ -287,7 +287,7 @@ async def ws_get_client_config( ) return - config = (await camera.async_get_webrtc_client_configuration()).to_frontend_dict() + config = camera.async_get_webrtc_client_configuration().to_frontend_dict() connection.send_result( msg["id"], config, diff --git a/homeassistant/components/nest/camera.py b/homeassistant/components/nest/camera.py index ee035ce8d11..2e94d5ad06b 100644 --- a/homeassistant/components/nest/camera.py +++ b/homeassistant/components/nest/camera.py @@ -28,7 +28,7 @@ from homeassistant.components.camera import ( ) from homeassistant.components.stream import CONF_EXTRA_PART_WAIT_TIME from homeassistant.config_entries import ConfigEntry -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_point_in_utc_time @@ -216,6 +216,7 @@ class NestCamera(Camera): raise HomeAssistantError(f"Nest API error: {err}") from err return stream.answer_sdp - async def _async_get_webrtc_client_configuration(self) -> WebRTCClientConfiguration: + @callback + def _async_get_webrtc_client_configuration(self) -> WebRTCClientConfiguration: """Return the WebRTC client configuration adjustable per integration.""" return WebRTCClientConfiguration(data_channel="dataSendChannel") diff --git a/tests/components/camera/test_webrtc.py b/tests/components/camera/test_webrtc.py index 632e673625f..616ed93116b 100644 --- a/tests/components/camera/test_webrtc.py +++ b/tests/components/camera/test_webrtc.py @@ -250,7 +250,7 @@ async def test_async_register_ice_server( assert not called camera = get_camera_from_entity_id(hass, "camera.demo_camera") - config = await camera.async_get_webrtc_client_configuration() + config = camera.async_get_webrtc_client_configuration() assert config.configuration.ice_servers == [ RTCIceServer(urls="stun:example.com"), @@ -275,7 +275,7 @@ async def test_async_register_ice_server( unregister_2 = async_register_ice_servers(hass, get_ice_servers_2) - config = await camera.async_get_webrtc_client_configuration() + config = camera.async_get_webrtc_client_configuration() assert config.configuration.ice_servers == [ RTCIceServer(urls="stun:example.com"), RTCIceServer(urls="turn:example.com"), @@ -292,7 +292,7 @@ async def test_async_register_ice_server( unregister() - config = await camera.async_get_webrtc_client_configuration() + config = camera.async_get_webrtc_client_configuration() assert config.configuration.ice_servers == [ RTCIceServer( urls=["stun:example2.com", "turn:example2.com"], @@ -306,7 +306,7 @@ async def test_async_register_ice_server( # unregister the second ICE server unregister_2() - config = await camera.async_get_webrtc_client_configuration() + config = camera.async_get_webrtc_client_configuration() assert config.configuration.ice_servers == []