From a3942e019b5155893cc0cd446e836f8796fa0951 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:50:35 +0200 Subject: [PATCH] Use remove_device helper in tests (2/2) (#116442) Use remove_device helper in tests (part 2) --- tests/components/august/test_init.py | 31 +++------------- tests/components/bond/common.py | 14 ------- tests/components/bond/test_init.py | 34 +++++------------ tests/components/fronius/__init__.py | 14 ------- tests/components/fronius/test_init.py | 11 ++---- tests/components/homekit_controller/common.py | 14 ------- .../homekit_controller/test_init.py | 14 +++---- tests/components/ibeacon/test_init.py | 30 +++------------ tests/components/jellyfin/test_init.py | 36 ++++-------------- tests/components/litterrobot/common.py | 14 ------- tests/components/litterrobot/test_init.py | 19 +++------- tests/components/netatmo/test_init.py | 35 +++--------------- tests/components/nexia/test_init.py | 37 ++++--------------- tests/components/onewire/test_init.py | 24 +++--------- tests/components/scrape/test_init.py | 31 +++------------- tests/components/sensibo/test_init.py | 31 +++------------- tests/components/unifiprotect/test_init.py | 37 ++++--------------- 17 files changed, 79 insertions(+), 347 deletions(-) diff --git a/tests/components/august/test_init.py b/tests/components/august/test_init.py index 6795491abe3..c62a5b55ac3 100644 --- a/tests/components/august/test_init.py +++ b/tests/components/august/test_init.py @@ -384,20 +384,6 @@ async def test_load_triggers_ble_discovery( } -async def remove_device(ws_client, device_id, config_entry_id): - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - async def test_device_remove_devices( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, @@ -411,20 +397,13 @@ async def test_device_remove_devices( entity = entity_registry.entities["lock.a6697750d607098bae8d6baa11ef8063_name"] device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device( - await hass_ws_client(hass), device_entry.id, config_entry.entry_id - ) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(device_entry.id, config_entry.entry_id) + assert not response["success"] dead_device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={(DOMAIN, "remove-device-id")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id - ) - is True - ) + response = await client.remove_device(dead_device_entry.id, config_entry.entry_id) + assert response["success"] diff --git a/tests/components/bond/common.py b/tests/components/bond/common.py index 0aff18e6ed1..0fcd2d4a99f 100644 --- a/tests/components/bond/common.py +++ b/tests/components/bond/common.py @@ -19,20 +19,6 @@ from homeassistant.util import utcnow from tests.common import MockConfigEntry, async_fire_time_changed -async def remove_device(ws_client, device_id, config_entry_id): - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - def ceiling_fan_with_breeze(name: str): """Create a ceiling fan with given name with breeze support.""" return { diff --git a/tests/components/bond/test_init.py b/tests/components/bond/test_init.py index 167cd9aa401..3ad589d2d10 100644 --- a/tests/components/bond/test_init.py +++ b/tests/components/bond/test_init.py @@ -24,7 +24,6 @@ from .common import ( patch_bond_version, patch_setup_entry, patch_start_bpup, - remove_device, setup_bond_entity, setup_platform, ) @@ -318,45 +317,30 @@ async def test_device_remove_devices( assert entity.unique_id == "test-hub-id_test-device-id" device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device( - await hass_ws_client(hass), device_entry.id, config_entry.entry_id - ) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(device_entry.id, config_entry.entry_id) + assert not response["success"] dead_device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={(DOMAIN, "test-hub-id", "remove-device-id")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id - ) - is True - ) + response = await client.remove_device(dead_device_entry.id, config_entry.entry_id) + assert response["success"] dead_device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={(DOMAIN, "wrong-hub-id", "test-device-id")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id - ) - is True - ) + response = await client.remove_device(dead_device_entry.id, config_entry.entry_id) + assert response["success"] hub_device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={(DOMAIN, "test-hub-id")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), hub_device_entry.id, config_entry.entry_id - ) - is False - ) + response = await client.remove_device(hub_device_entry.id, config_entry.entry_id) + assert not response["success"] async def test_smart_by_bond_v3_firmware(hass: HomeAssistant) -> None: diff --git a/tests/components/fronius/__init__.py b/tests/components/fronius/__init__.py index 3757abab928..f1630d6cd7e 100644 --- a/tests/components/fronius/__init__.py +++ b/tests/components/fronius/__init__.py @@ -126,17 +126,3 @@ async def enable_all_entities(hass, freezer, config_entry_id, time_till_next_upd freezer.tick(time_till_next_update) async_fire_time_changed(hass) await hass.async_block_till_done() - - -async def remove_device(ws_client, device_id, config_entry_id): - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] diff --git a/tests/components/fronius/test_init.py b/tests/components/fronius/test_init.py index 282b2c3fa76..9d570785073 100644 --- a/tests/components/fronius/test_init.py +++ b/tests/components/fronius/test_init.py @@ -12,7 +12,7 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util -from . import mock_responses, remove_device, setup_fronius_integration +from . import mock_responses, setup_fronius_integration from tests.common import async_fire_time_changed from tests.test_util.aiohttp import AiohttpClientMocker @@ -159,11 +159,8 @@ async def test_device_remove_devices( ) inverter_1 = device_registry.async_get_device(identifiers={(DOMAIN, "12345678")}) - assert ( - await remove_device( - await hass_ws_client(hass), inverter_1.id, config_entry.entry_id - ) - is True - ) + client = await hass_ws_client(hass) + response = await client.remove_device(inverter_1.id, config_entry.entry_id) + assert response["success"] assert not device_registry.async_get_device(identifiers={(DOMAIN, "12345678")}) diff --git a/tests/components/homekit_controller/common.py b/tests/components/homekit_controller/common.py index 95bf2530b2d..1360b463e4a 100644 --- a/tests/components/homekit_controller/common.py +++ b/tests/components/homekit_controller/common.py @@ -399,20 +399,6 @@ async def assert_devices_and_entities_created( assert root_device.via_device_id is None -async def remove_device(ws_client, device_id, config_entry_id): - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - def get_next_aid(): """Get next aid.""" return model_mixin.id_counter + 1 diff --git a/tests/components/homekit_controller/test_init.py b/tests/components/homekit_controller/test_init.py index 9d2022f6b1c..db7fead9139 100644 --- a/tests/components/homekit_controller/test_init.py +++ b/tests/components/homekit_controller/test_init.py @@ -23,7 +23,6 @@ from homeassistant.util.dt import utcnow from .common import ( Helper, - remove_device, setup_accessories_from_file, setup_test_accessories, setup_test_accessories_with_controller, @@ -99,19 +98,16 @@ async def test_device_remove_devices( entity = entity_registry.entities[ALIVE_DEVICE_ENTITY_ID] live_device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device(await hass_ws_client(hass), live_device_entry.id, entry_id) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(live_device_entry.id, entry_id) + assert not response["success"] dead_device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={("homekit_controller:accessory-id", "E9:88:E7:B8:B4:40:aid:1")}, ) - assert ( - await remove_device(await hass_ws_client(hass), dead_device_entry.id, entry_id) - is True - ) + response = await client.remove_device(dead_device_entry.id, entry_id) + assert response["success"] async def test_offline_device_raises(hass: HomeAssistant, controller) -> None: diff --git a/tests/components/ibeacon/test_init.py b/tests/components/ibeacon/test_init.py index 99c45b3dfe7..5a30417efe1 100644 --- a/tests/components/ibeacon/test_init.py +++ b/tests/components/ibeacon/test_init.py @@ -19,20 +19,6 @@ def mock_bluetooth(enable_bluetooth): """Auto mock bluetooth.""" -async def remove_device(ws_client, device_id, config_entry_id): - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - async def test_device_remove_devices( hass: HomeAssistant, device_registry: dr.DeviceRegistry, @@ -58,17 +44,13 @@ async def test_device_remove_devices( ) }, ) - assert ( - await remove_device(await hass_ws_client(hass), device_entry.id, entry.entry_id) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(device_entry.id, entry.entry_id) + assert not response["success"] + dead_device_entry = device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, "not_seen")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), dead_device_entry.id, entry.entry_id - ) - is True - ) + response = await client.remove_device(dead_device_entry.id, entry.entry_id) + assert response["success"] diff --git a/tests/components/jellyfin/test_init.py b/tests/components/jellyfin/test_init.py index 6e6a0f7219b..51d7af2ae94 100644 --- a/tests/components/jellyfin/test_init.py +++ b/tests/components/jellyfin/test_init.py @@ -11,23 +11,7 @@ from homeassistant.setup import async_setup_component from . import async_load_json_fixture from tests.common import MockConfigEntry -from tests.typing import MockHAClientWebSocket, WebSocketGenerator - - -async def remove_device( - ws_client: MockHAClientWebSocket, device_id: str, config_entry_id: str -) -> bool: - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 1, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] +from tests.typing import WebSocketGenerator async def test_config_entry_not_ready( @@ -116,19 +100,15 @@ async def test_device_remove_devices( ) }, ) - assert ( - await remove_device( - await hass_ws_client(hass), device_entry.id, mock_config_entry.entry_id - ) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(device_entry.id, mock_config_entry.entry_id) + assert not response["success"] + old_device_entry = device_registry.async_get_or_create( config_entry_id=mock_config_entry.entry_id, identifiers={(DOMAIN, "OLD-DEVICE-UUID")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), old_device_entry.id, mock_config_entry.entry_id - ) - is True + response = await client.remove_device( + old_device_entry.id, mock_config_entry.entry_id ) + assert response["success"] diff --git a/tests/components/litterrobot/common.py b/tests/components/litterrobot/common.py index cac81aad4ef..8849392b3dd 100644 --- a/tests/components/litterrobot/common.py +++ b/tests/components/litterrobot/common.py @@ -144,17 +144,3 @@ FEEDER_ROBOT_DATA = { } VACUUM_ENTITY_ID = "vacuum.test_litter_box" - - -async def remove_device(ws_client, device_id, config_entry_id): - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] diff --git a/tests/components/litterrobot/test_init.py b/tests/components/litterrobot/test_init.py index 60f359f08f0..f4ad12aeb20 100644 --- a/tests/components/litterrobot/test_init.py +++ b/tests/components/litterrobot/test_init.py @@ -17,7 +17,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component -from .common import CONFIG, VACUUM_ENTITY_ID, remove_device +from .common import CONFIG, VACUUM_ENTITY_ID from .conftest import setup_integration from tests.common import MockConfigEntry @@ -87,20 +87,13 @@ async def test_device_remove_devices( assert entity.unique_id == "LR3C012345-litter_box" device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device( - await hass_ws_client(hass), device_entry.id, config_entry.entry_id - ) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(device_entry.id, config_entry.entry_id) + assert not response["success"] dead_device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={(litterrobot.DOMAIN, "test-serial", "remove-serial")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id - ) - is True - ) + response = await client.remove_device(dead_device_entry.id, config_entry.entry_id) + assert response["success"] diff --git a/tests/components/netatmo/test_init.py b/tests/components/netatmo/test_init.py index 55af74b3373..8d8dfae9eeb 100644 --- a/tests/components/netatmo/test_init.py +++ b/tests/components/netatmo/test_init.py @@ -31,7 +31,7 @@ from tests.common import ( async_get_persistent_notifications, ) from tests.components.cloud import mock_cloud -from tests.typing import MockHAClientWebSocket, WebSocketGenerator +from tests.typing import WebSocketGenerator # Fake webhook thermostat mode change to "Max" FAKE_WEBHOOK = { @@ -517,22 +517,6 @@ async def test_devices( assert device_entry == snapshot(name=f"{identifier[0]}-{identifier[1]}") -async def remove_device( - ws_client: MockHAClientWebSocket, device_id: str, config_entry_id: str -) -> bool: - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 1, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - async def test_device_remove_devices( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, @@ -554,20 +538,13 @@ async def test_device_remove_devices( entity = entity_registry.async_get(climate_entity_livingroom) device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device( - await hass_ws_client(hass), device_entry.id, config_entry.entry_id - ) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(device_entry.id, config_entry.entry_id) + assert not response["success"] dead_device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={(DOMAIN, "remove-device-id")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id - ) - is True - ) + response = await client.remove_device(dead_device_entry.id, config_entry.entry_id) + assert response["success"] diff --git a/tests/components/nexia/test_init.py b/tests/components/nexia/test_init.py index ec84748830a..58ad74c859d 100644 --- a/tests/components/nexia/test_init.py +++ b/tests/components/nexia/test_init.py @@ -20,20 +20,6 @@ async def test_setup_retry_client_os_error(hass: HomeAssistant) -> None: assert config_entry.state is ConfigEntryState.SETUP_RETRY -async def remove_device(ws_client, device_id, config_entry_id): - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - async def test_device_remove_devices( hass: HomeAssistant, hass_ws_client: WebSocketGenerator ) -> None: @@ -47,27 +33,18 @@ async def test_device_remove_devices( entity = registry.entities["sensor.nick_office_temperature"] live_zone_device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device( - await hass_ws_client(hass), live_zone_device_entry.id, entry_id - ) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(live_zone_device_entry.id, entry_id) + assert not response["success"] entity = registry.entities["sensor.master_suite_humidity"] live_thermostat_device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device( - await hass_ws_client(hass), live_thermostat_device_entry.id, entry_id - ) - is False - ) + response = await client.remove_device(live_thermostat_device_entry.id, entry_id) + assert not response["success"] dead_device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, identifiers={(DOMAIN, "unused")}, ) - assert ( - await remove_device(await hass_ws_client(hass), dead_device_entry.id, entry_id) - is True - ) + response = await client.remove_device(dead_device_entry.id, entry_id) + assert response["success"] diff --git a/tests/components/onewire/test_init.py b/tests/components/onewire/test_init.py index 991277d8329..a1a24cd8f83 100644 --- a/tests/components/onewire/test_init.py +++ b/tests/components/onewire/test_init.py @@ -3,7 +3,6 @@ from copy import deepcopy from unittest.mock import MagicMock, patch -import aiohttp from pyownet import protocol import pytest @@ -19,22 +18,6 @@ from . import setup_owproxy_mock_devices from tests.typing import WebSocketGenerator -async def remove_device( - ws_client: aiohttp.ClientWebSocketResponse, device_id: str, config_entry_id: str -) -> bool: - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 1, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - @pytest.mark.usefixtures("owproxy_with_connerror") async def test_connect_failure(hass: HomeAssistant, config_entry: ConfigEntry) -> None: """Test connection failure raises ConfigEntryNotReady.""" @@ -125,12 +108,15 @@ async def test_registry_cleanup( # Try to remove "10.111111111111" - fails as it is live device = device_registry.async_get_device(identifiers={(DOMAIN, live_id)}) - assert await remove_device(await hass_ws_client(hass), device.id, entry_id) is False + client = await hass_ws_client(hass) + response = await client.remove_device(device.id, entry_id) + assert not response["success"] assert len(dr.async_entries_for_config_entry(device_registry, entry_id)) == 2 assert device_registry.async_get_device(identifiers={(DOMAIN, live_id)}) is not None # Try to remove "28.111111111111" - succeeds as it is dead device = device_registry.async_get_device(identifiers={(DOMAIN, dead_id)}) - assert await remove_device(await hass_ws_client(hass), device.id, entry_id) is True + response = await client.remove_device(device.id, entry_id) + assert response["success"] assert len(dr.async_entries_for_config_entry(device_registry, entry_id)) == 1 assert device_registry.async_get_device(identifiers={(DOMAIN, dead_id)}) is None diff --git a/tests/components/scrape/test_init.py b/tests/components/scrape/test_init.py index db1a89e1ce4..09036f213dc 100644 --- a/tests/components/scrape/test_init.py +++ b/tests/components/scrape/test_init.py @@ -129,20 +129,6 @@ async def test_unload_entry(hass: HomeAssistant, loaded_entry: MockConfigEntry) assert loaded_entry.state is ConfigEntryState.NOT_LOADED -async def remove_device(ws_client, device_id, config_entry_id): - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - async def test_device_remove_devices( hass: HomeAssistant, loaded_entry: MockConfigEntry, @@ -155,20 +141,13 @@ async def test_device_remove_devices( device_registry = dr.async_get(hass) device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device( - await hass_ws_client(hass), device_entry.id, loaded_entry.entry_id - ) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(device_entry.id, loaded_entry.entry_id) + assert not response["success"] dead_device_entry = device_registry.async_get_or_create( config_entry_id=loaded_entry.entry_id, identifiers={(DOMAIN, "remove-device-id")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), dead_device_entry.id, loaded_entry.entry_id - ) - is True - ) + response = await client.remove_device(dead_device_entry.id, loaded_entry.entry_id) + assert response["success"] diff --git a/tests/components/sensibo/test_init.py b/tests/components/sensibo/test_init.py index 9ab30edf177..7138da9191f 100644 --- a/tests/components/sensibo/test_init.py +++ b/tests/components/sensibo/test_init.py @@ -152,20 +152,6 @@ async def test_unload_entry(hass: HomeAssistant, get_data: SensiboData) -> None: assert entry.state is ConfigEntryState.NOT_LOADED -async def remove_device(ws_client, device_id, config_entry_id): - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - async def test_device_remove_devices( hass: HomeAssistant, load_int: ConfigEntry, @@ -178,20 +164,13 @@ async def test_device_remove_devices( device_registry = dr.async_get(hass) device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device( - await hass_ws_client(hass), device_entry.id, load_int.entry_id - ) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(device_entry.id, load_int.entry_id) + assert not response["success"] dead_device_entry = device_registry.async_get_or_create( config_entry_id=load_int.entry_id, identifiers={(DOMAIN, "remove-device-id")}, ) - assert ( - await remove_device( - await hass_ws_client(hass), dead_device_entry.id, load_int.entry_id - ) - is True - ) + response = await client.remove_device(dead_device_entry.id, load_int.entry_id) + assert response["success"] diff --git a/tests/components/unifiprotect/test_init.py b/tests/components/unifiprotect/test_init.py index 0e3fd42e28b..69374fd19d4 100644 --- a/tests/components/unifiprotect/test_init.py +++ b/tests/components/unifiprotect/test_init.py @@ -4,7 +4,6 @@ from __future__ import annotations from unittest.mock import AsyncMock, patch -import aiohttp from pyunifiprotect import NotAuthorized, NvrError, ProtectApiClient from pyunifiprotect.data import NVR, Bootstrap, CloudAccount, Light @@ -26,22 +25,6 @@ from tests.common import MockConfigEntry from tests.typing import WebSocketGenerator -async def remove_device( - ws_client: aiohttp.ClientWebSocketResponse, device_id: str, config_entry_id: str -) -> bool: - """Remove config entry from a device.""" - await ws_client.send_json( - { - "id": 5, - "type": "config/device_registry/remove_config_entry", - "config_entry_id": config_entry_id, - "device_id": device_id, - } - ) - response = await ws_client.receive_json() - return response["success"] - - async def test_setup(hass: HomeAssistant, ufp: MockUFPFixture) -> None: """Test working setup of unifiprotect entry.""" @@ -275,19 +258,16 @@ async def test_device_remove_devices( device_registry = dr.async_get(hass) live_device_entry = device_registry.async_get(entity.device_id) - assert ( - await remove_device(await hass_ws_client(hass), live_device_entry.id, entry_id) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(live_device_entry.id, entry_id) + assert not response["success"] 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")}, ) - assert ( - await remove_device(await hass_ws_client(hass), dead_device_entry.id, entry_id) - is True - ) + response = await client.remove_device(dead_device_entry.id, entry_id) + assert response["success"] async def test_device_remove_devices_nvr( @@ -306,7 +286,6 @@ async def test_device_remove_devices_nvr( device_registry = dr.async_get(hass) live_device_entry = list(device_registry.devices.values())[0] - assert ( - await remove_device(await hass_ws_client(hass), live_device_entry.id, entry_id) - is False - ) + client = await hass_ws_client(hass) + response = await client.remove_device(live_device_entry.id, entry_id) + assert not response["success"]