UniFi Protect removing early access checks and issue creation (#147432)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Raphael Hehl
2025-06-27 17:15:34 +02:00
committed by GitHub
co-authored by Copilot
parent 4b02f22724
commit 8a18dea8c7
8 changed files with 50 additions and 235 deletions
@@ -4,7 +4,7 @@ from __future__ import annotations
from dataclasses import asdict
import socket
from unittest.mock import patch
from unittest.mock import AsyncMock, Mock, patch
import pytest
from uiprotect import NotAuthorized, NvrError, ProtectApiClient
@@ -325,7 +325,6 @@ async def test_form_options(hass: HomeAssistant, ufp_client: ProtectApiClient) -
"disable_rtsp": True,
"override_connection_host": True,
"max_media": 1000,
"allow_ea_channel": False,
}
await hass.async_block_till_done()
await hass.config_entries.async_unload(mock_config.entry_id)
@@ -794,6 +793,7 @@ async def test_discovered_by_unifi_discovery_direct_connect_on_different_interfa
},
unique_id="FFFFFFAAAAAA",
)
mock_config.runtime_data = Mock(async_stop=AsyncMock())
mock_config.add_to_hass(hass)
other_ip_dict = UNIFI_DISCOVERY_DICT.copy()
@@ -855,7 +855,7 @@ async def test_discovered_by_unifi_discovery_direct_connect_on_different_interfa
"port": 443,
"verify_ssl": True,
}
assert len(mock_setup_entry.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 2
assert len(mock_setup.mock_calls) == 1
@@ -2,7 +2,6 @@
from uiprotect.data import NVR, Light
from homeassistant.components.unifiprotect.const import CONF_ALLOW_EA
from homeassistant.core import HomeAssistant
from .utils import MockUFPFixture, init_entry
@@ -22,7 +21,6 @@ async def test_diagnostics(
await init_entry(hass, ufp, [light])
options = dict(ufp.entry.options)
options[CONF_ALLOW_EA] = True
hass.config_entries.async_update_entry(ufp.entry, options=options)
await hass.async_block_till_done()
@@ -30,7 +28,6 @@ async def test_diagnostics(
assert "options" in diag and isinstance(diag["options"], dict)
options = diag["options"]
assert options[CONF_ALLOW_EA] is True
assert "bootstrap" in diag and isinstance(diag["bootstrap"], dict)
bootstrap = diag["bootstrap"]
@@ -11,6 +11,7 @@ from uiprotect.data import NVR, Bootstrap, CloudAccount, Light
from homeassistant.components.unifiprotect.const import (
AUTH_RETRIES,
CONF_ALLOW_EA,
CONF_DISABLE_RTSP,
DOMAIN,
)
@@ -345,3 +346,24 @@ async def test_async_ufp_instance_for_config_entry_ids(
result = async_ufp_instance_for_config_entry_ids(hass, entry_ids)
assert result == expected_result
async def test_migrate_entry_version_2(hass: HomeAssistant) -> None:
"""Test remove CONF_ALLOW_EA from options while migrating a 1 config entry to 2."""
with (
patch(
"homeassistant.components.unifiprotect.async_setup_entry", return_value=True
),
patch("homeassistant.components.unifiprotect.async_start_discovery"),
):
entry = MockConfigEntry(
domain=DOMAIN,
data={"test": "1", "test2": "2", CONF_ALLOW_EA: "True"},
version=1,
unique_id="123456",
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
assert entry.version == 2
assert entry.options.get(CONF_ALLOW_EA) is None
assert entry.unique_id == "123456"
+2 -106
View File
@@ -2,8 +2,8 @@
from __future__ import annotations
from copy import copy, deepcopy
from unittest.mock import AsyncMock, Mock
from copy import deepcopy
from unittest.mock import AsyncMock
from uiprotect.data import Camera, CloudAccount, ModelType, Version
@@ -21,110 +21,6 @@ from tests.components.repairs import (
from tests.typing import ClientSessionGenerator, WebSocketGenerator
async def test_ea_warning_ignore(
hass: HomeAssistant,
ufp: MockUFPFixture,
hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test EA warning is created if using prerelease version of Protect."""
ufp.api.bootstrap.nvr.release_channel = "beta"
ufp.api.bootstrap.nvr.version = Version("1.21.0-beta.2")
version = ufp.api.bootstrap.nvr.version
assert version.is_prerelease
await init_entry(hass, ufp, [])
await async_process_repairs_platforms(hass)
ws_client = await hass_ws_client(hass)
client = await hass_client()
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
issue = None
for i in msg["result"]["issues"]:
if i["issue_id"] == "ea_channel_warning":
issue = i
assert issue is not None
data = await start_repair_fix_flow(client, DOMAIN, "ea_channel_warning")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
"learn_more": "https://www.home-assistant.io/integrations/unifiprotect#software-support",
"version": str(version),
}
assert data["step_id"] == "start"
data = await process_repair_fix_flow(client, flow_id)
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
"learn_more": "https://www.home-assistant.io/integrations/unifiprotect#software-support",
"version": str(version),
}
assert data["step_id"] == "confirm"
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"
async def test_ea_warning_fix(
hass: HomeAssistant,
ufp: MockUFPFixture,
hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test EA warning is created if using prerelease version of Protect."""
ufp.api.bootstrap.nvr.release_channel = "beta"
ufp.api.bootstrap.nvr.version = Version("1.21.0-beta.2")
version = ufp.api.bootstrap.nvr.version
assert version.is_prerelease
await init_entry(hass, ufp, [])
await async_process_repairs_platforms(hass)
ws_client = await hass_ws_client(hass)
client = await hass_client()
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
issue = None
for i in msg["result"]["issues"]:
if i["issue_id"] == "ea_channel_warning":
issue = i
assert issue is not None
data = await start_repair_fix_flow(client, DOMAIN, "ea_channel_warning")
flow_id = data["flow_id"]
assert data["description_placeholders"] == {
"learn_more": "https://www.home-assistant.io/integrations/unifiprotect#software-support",
"version": str(version),
}
assert data["step_id"] == "start"
new_nvr = copy(ufp.api.bootstrap.nvr)
new_nvr.release_channel = "release"
new_nvr.version = Version("2.2.6")
mock_msg = Mock()
mock_msg.changed_data = {"version": "2.2.6", "releaseChannel": "release"}
mock_msg.new_obj = new_nvr
ufp.api.bootstrap.nvr = new_nvr
ufp.ws_msg(mock_msg)
await hass.async_block_till_done()
data = await process_repair_fix_flow(client, flow_id)
assert data["type"] == "create_entry"
async def test_cloud_user_fix(
hass: HomeAssistant,
ufp: MockUFPFixture,