mirror of
https://github.com/elisspace/core.git
synced 2026-09-30 06:19:55 +00:00
Revert "Add ability to ignore devices for UniFi Protect" (#77916)
This commit is contained in:
@@ -68,7 +68,6 @@ def mock_ufp_config_entry():
|
||||
"port": 443,
|
||||
"verify_ssl": False,
|
||||
},
|
||||
options={"ignored_devices": "FFFFFFFFFFFF,test"},
|
||||
version=2,
|
||||
)
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ from homeassistant.components import dhcp, ssdp
|
||||
from homeassistant.components.unifiprotect.const import (
|
||||
CONF_ALL_UPDATES,
|
||||
CONF_DISABLE_RTSP,
|
||||
CONF_IGNORED,
|
||||
CONF_OVERRIDE_CHOST,
|
||||
DOMAIN,
|
||||
)
|
||||
@@ -270,52 +269,10 @@ async def test_form_options(hass: HomeAssistant, ufp_client: ProtectApiClient) -
|
||||
"all_updates": True,
|
||||
"disable_rtsp": True,
|
||||
"override_connection_host": True,
|
||||
"max_media": 1000,
|
||||
}
|
||||
|
||||
|
||||
async def test_form_options_invalid_mac(
|
||||
hass: HomeAssistant, ufp_client: ProtectApiClient
|
||||
) -> None:
|
||||
"""Test we handle options flows."""
|
||||
mock_config = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
"host": "1.1.1.1",
|
||||
"username": "test-username",
|
||||
"password": "test-password",
|
||||
"id": "UnifiProtect",
|
||||
"port": 443,
|
||||
"verify_ssl": False,
|
||||
"max_media": 1000,
|
||||
},
|
||||
version=2,
|
||||
unique_id=dr.format_mac(MAC_ADDR),
|
||||
)
|
||||
mock_config.add_to_hass(hass)
|
||||
|
||||
with _patch_discovery(), patch(
|
||||
"homeassistant.components.unifiprotect.ProtectApiClient"
|
||||
) as mock_api:
|
||||
mock_api.return_value = ufp_client
|
||||
|
||||
await hass.config_entries.async_setup(mock_config.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_config.state == config_entries.ConfigEntryState.LOADED
|
||||
|
||||
result = await hass.config_entries.options.async_init(mock_config.entry_id)
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert not result["errors"]
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
result2 = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
{CONF_IGNORED: "test,test2"},
|
||||
)
|
||||
|
||||
assert result2["type"] == FlowResultType.FORM
|
||||
assert result2["errors"] == {CONF_IGNORED: "invalid_mac_list"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"source, data",
|
||||
[
|
||||
|
||||
@@ -7,21 +7,20 @@ from unittest.mock import AsyncMock, patch
|
||||
|
||||
import aiohttp
|
||||
from pyunifiprotect import NotAuthorized, NvrError, ProtectApiClient
|
||||
from pyunifiprotect.data import NVR, Bootstrap, Doorlock, Light, Sensor
|
||||
from pyunifiprotect.data import NVR, Bootstrap, Light
|
||||
|
||||
from homeassistant.components.unifiprotect.const import (
|
||||
CONF_DISABLE_RTSP,
|
||||
CONF_IGNORED,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import _patch_discovery
|
||||
from .utils import MockUFPFixture, get_device_from_ufp_device, init_entry, time_changed
|
||||
from .utils import MockUFPFixture, init_entry, time_changed
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -212,38 +211,28 @@ async def test_device_remove_devices(
|
||||
hass: HomeAssistant,
|
||||
ufp: MockUFPFixture,
|
||||
light: Light,
|
||||
doorlock: Doorlock,
|
||||
sensor: Sensor,
|
||||
hass_ws_client: Callable[
|
||||
[HomeAssistant], Awaitable[aiohttp.ClientWebSocketResponse]
|
||||
],
|
||||
) -> None:
|
||||
"""Test we can only remove a device that no longer exists."""
|
||||
|
||||
sensor.mac = "FFFFFFFFFFFF"
|
||||
|
||||
await init_entry(hass, ufp, [light, doorlock, sensor], regenerate_ids=False)
|
||||
await init_entry(hass, ufp, [light])
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
|
||||
entity_id = "light.test_light"
|
||||
entry_id = ufp.entry.entry_id
|
||||
|
||||
registry: er.EntityRegistry = er.async_get(hass)
|
||||
entity = registry.async_get(entity_id)
|
||||
assert entity is not None
|
||||
device_registry = dr.async_get(hass)
|
||||
|
||||
light_device = get_device_from_ufp_device(hass, light)
|
||||
assert light_device is not None
|
||||
live_device_entry = device_registry.async_get(entity.device_id)
|
||||
assert (
|
||||
await remove_device(await hass_ws_client(hass), light_device.id, entry_id)
|
||||
is True
|
||||
await remove_device(await hass_ws_client(hass), live_device_entry.id, entry_id)
|
||||
is False
|
||||
)
|
||||
|
||||
doorlock_device = get_device_from_ufp_device(hass, doorlock)
|
||||
assert (
|
||||
await remove_device(await hass_ws_client(hass), doorlock_device.id, entry_id)
|
||||
is True
|
||||
)
|
||||
|
||||
sensor_device = get_device_from_ufp_device(hass, sensor)
|
||||
assert sensor_device is None
|
||||
|
||||
dead_device_entry = device_registry.async_get_or_create(
|
||||
config_entry_id=entry_id,
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "e9:88:e7:b8:b4:40")},
|
||||
@@ -253,10 +242,6 @@ async def test_device_remove_devices(
|
||||
is True
|
||||
)
|
||||
|
||||
await time_changed(hass, 60)
|
||||
entry = hass.config_entries.async_get_entry(entry_id)
|
||||
entry.options[CONF_IGNORED] == f"{light.mac},{doorlock.mac}"
|
||||
|
||||
|
||||
async def test_device_remove_devices_nvr(
|
||||
hass: HomeAssistant,
|
||||
|
||||
@@ -23,7 +23,7 @@ from pyunifiprotect.test_util.anonymize import random_hex
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant, split_entity_id
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
@@ -229,13 +229,3 @@ async def adopt_devices(
|
||||
ufp.ws_msg(mock_msg)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
def get_device_from_ufp_device(
|
||||
hass: HomeAssistant, device: ProtectAdoptableDeviceModel
|
||||
) -> dr.DeviceEntry | None:
|
||||
"""Return all device by type."""
|
||||
registry = dr.async_get(hass)
|
||||
return registry.async_get_device(
|
||||
identifiers=set(), connections={(dr.CONNECTION_NETWORK_MAC, device.mac)}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user