From 3367f81c4e87b2be1f16da4b2c49e04e49da3905 Mon Sep 17 00:00:00 2001 From: rahehl <7577984+RaHehl@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:54:46 +0000 Subject: [PATCH 1/4] unifiprotect prevent RTSP repair for third-party cameras and add corresponding test --- .../components/unifiprotect/camera.py | 2 ++ tests/components/unifiprotect/test_repairs.py | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/homeassistant/components/unifiprotect/camera.py b/homeassistant/components/unifiprotect/camera.py index a40939be9177f0..9348c94edd8300 100644 --- a/homeassistant/components/unifiprotect/camera.py +++ b/homeassistant/components/unifiprotect/camera.py @@ -38,6 +38,8 @@ def _create_rtsp_repair( hass: HomeAssistant, entry: UFPConfigEntry, data: ProtectData, camera: UFPCamera ) -> None: + if camera.is_third_party_camera: + return edit_key = "readonly" if camera.can_write(data.api.bootstrap.auth_user): edit_key = "writable" diff --git a/tests/components/unifiprotect/test_repairs.py b/tests/components/unifiprotect/test_repairs.py index adb9555e6ea472..b6f7b914b8d6a3 100644 --- a/tests/components/unifiprotect/test_repairs.py +++ b/tests/components/unifiprotect/test_repairs.py @@ -363,3 +363,30 @@ async def test_rtsp_writable_fix_when_not_setup( ufp.api.update_device.assert_called_with( ModelType.CAMERA, doorbell.id, {"channels": channels} ) + + +async def test_rtsp_no_fix_if_third_party( + hass: HomeAssistant, + ufp: MockUFPFixture, + doorbell: Camera, + hass_ws_client: WebSocketGenerator, +) -> None: + """Test no RTSP disabled warning if camera is third-party.""" + + for channel in doorbell.channels: + channel.is_rtsp_enabled = False + for user in ufp.api.bootstrap.users.values(): + user.all_permissions = [] + + ufp.api.get_camera = AsyncMock(return_value=doorbell) + doorbell.is_third_party_camera = True + + await init_entry(hass, ufp, [doorbell]) + await async_process_repairs_platforms(hass) + ws_client = await hass_ws_client(hass) + + await ws_client.send_json({"id": 1, "type": "repairs/list_issues"}) + msg = await ws_client.receive_json() + + assert msg["success"] + assert len(msg["result"]["issues"]) == 0 From ae034c2873f2293e68755a58ffe6751e83cb8421 Mon Sep 17 00:00:00 2001 From: rahehl <7577984+RaHehl@users.noreply.github.com> Date: Tue, 3 Dec 2024 21:20:15 +0000 Subject: [PATCH 2/4] unifiprotect move third party camera check from _create_rtsp_repair to _get_camera_channels --- homeassistant/components/unifiprotect/camera.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/unifiprotect/camera.py b/homeassistant/components/unifiprotect/camera.py index 9348c94edd8300..922834e750126a 100644 --- a/homeassistant/components/unifiprotect/camera.py +++ b/homeassistant/components/unifiprotect/camera.py @@ -38,8 +38,6 @@ def _create_rtsp_repair( hass: HomeAssistant, entry: UFPConfigEntry, data: ProtectData, camera: UFPCamera ) -> None: - if camera.is_third_party_camera: - return edit_key = "readonly" if camera.can_write(data.api.bootstrap.auth_user): edit_key = "writable" @@ -93,7 +91,8 @@ def _get_camera_channels( # no RTSP enabled use first channel with no stream if is_default: - _create_rtsp_repair(hass, entry, data, camera) + if not camera.is_third_party_camera: + _create_rtsp_repair(hass, entry, data, camera) yield camera, camera.channels[0], True else: ir.async_delete_issue(hass, DOMAIN, f"rtsp_disabled_{camera.id}") From 28d6d64f8bc73ce04a2b63c39b79327111f80c38 Mon Sep 17 00:00:00 2001 From: rahehl <7577984+RaHehl@users.noreply.github.com> Date: Tue, 3 Dec 2024 21:28:19 +0000 Subject: [PATCH 3/4] unifiprotect optimize RTSP repair call to cleanup issues if thirdparty --- homeassistant/components/unifiprotect/camera.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/unifiprotect/camera.py b/homeassistant/components/unifiprotect/camera.py index 922834e750126a..0b1c03b8dd6058 100644 --- a/homeassistant/components/unifiprotect/camera.py +++ b/homeassistant/components/unifiprotect/camera.py @@ -90,9 +90,8 @@ def _get_camera_channels( is_default = False # no RTSP enabled use first channel with no stream - if is_default: - if not camera.is_third_party_camera: - _create_rtsp_repair(hass, entry, data, camera) + if is_default and not camera.is_third_party_camera: + _create_rtsp_repair(hass, entry, data, camera) yield camera, camera.channels[0], True else: ir.async_delete_issue(hass, DOMAIN, f"rtsp_disabled_{camera.id}") From 69b6c40d916d27e84d83b23a14c715426f972ad4 Mon Sep 17 00:00:00 2001 From: Raphael Hehl <7577984+RaHehl@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:02:29 +0100 Subject: [PATCH 4/4] Update tests/components/unifiprotect/test_repairs.py Co-authored-by: J. Nick Koston --- tests/components/unifiprotect/test_repairs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/unifiprotect/test_repairs.py b/tests/components/unifiprotect/test_repairs.py index b6f7b914b8d6a3..1117038bbd0c83 100644 --- a/tests/components/unifiprotect/test_repairs.py +++ b/tests/components/unifiprotect/test_repairs.py @@ -389,4 +389,4 @@ async def test_rtsp_no_fix_if_third_party( msg = await ws_client.receive_json() assert msg["success"] - assert len(msg["result"]["issues"]) == 0 + assert not msg["result"]["issues"]