Guide users to migrate from Ubiquiti Cloud Accounts to local for UniFi Protect (#111018)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Christopher Bailey 2024-02-21 00:32:47 -05:00 committed by GitHub
parent fb04df5392
commit 7eb6614818
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 260 additions and 40 deletions

View file

@ -5,7 +5,7 @@ from copy import copy
from http import HTTPStatus
from unittest.mock import Mock
from pyunifiprotect.data import Version
from pyunifiprotect.data import CloudAccount, Version
from homeassistant.components.repairs.issue_handler import (
async_process_repairs_platforms,
@ -15,6 +15,7 @@ from homeassistant.components.repairs.websocket_api import (
RepairsFlowResourceView,
)
from homeassistant.components.unifiprotect.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH
from homeassistant.core import HomeAssistant
from .utils import MockUFPFixture, init_entry
@ -54,7 +55,10 @@ async def test_ea_warning_ignore(
data = await resp.json()
flow_id = data["flow_id"]
assert data["description_placeholders"] == {"version": str(version)}
assert data["description_placeholders"] == {
"learn_more": "https://www.home-assistant.io/integrations/unifiprotect#about-unifi-early-access",
"version": str(version),
}
assert data["step_id"] == "start"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
@ -63,7 +67,10 @@ async def test_ea_warning_ignore(
data = await resp.json()
flow_id = data["flow_id"]
assert data["description_placeholders"] == {"version": str(version)}
assert data["description_placeholders"] == {
"learn_more": "https://www.home-assistant.io/integrations/unifiprotect#about-unifi-early-access",
"version": str(version),
}
assert data["step_id"] == "confirm"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
@ -106,7 +113,10 @@ async def test_ea_warning_fix(
data = await resp.json()
flow_id = data["flow_id"]
assert data["description_placeholders"] == {"version": str(version)}
assert data["description_placeholders"] == {
"learn_more": "https://www.home-assistant.io/integrations/unifiprotect#about-unifi-early-access",
"version": str(version),
}
assert data["step_id"] == "start"
new_nvr = copy(ufp.api.bootstrap.nvr)
@ -125,3 +135,50 @@ async def test_ea_warning_fix(
data = await resp.json()
assert data["type"] == "create_entry"
async def test_cloud_user_fix(
hass: HomeAssistant,
ufp: MockUFPFixture,
cloud_account: CloudAccount,
hass_client: ClientSessionGenerator,
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test EA warning is created if using prerelease version of Protect."""
ufp.api.bootstrap.nvr.version = Version("2.2.6")
user = ufp.api.bootstrap.users[ufp.api.bootstrap.auth_user_id]
user.cloud_account = cloud_account
ufp.api.bootstrap.users[ufp.api.bootstrap.auth_user_id] = user
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"] == "cloud_user":
issue = i
assert issue is not None
url = RepairsFlowIndexView.url
resp = await client.post(url, json={"handler": DOMAIN, "issue_id": "cloud_user"})
assert resp.status == HTTPStatus.OK
data = await resp.json()
flow_id = data["flow_id"]
assert data["step_id"] == "confirm"
url = RepairsFlowResourceView.url.format(flow_id=flow_id)
resp = await client.post(url)
assert resp.status == HTTPStatus.OK
data = await resp.json()
assert data["type"] == "create_entry"
await hass.async_block_till_done()
assert any(ufp.entry.async_get_active_flows(hass, {SOURCE_REAUTH}))