Use remove_device helper in tests (2/2) (#116442)
Use remove_device helper in tests (part 2)
This commit is contained in:
parent
d84d2109c2
commit
a3942e019b
17 changed files with 79 additions and 347 deletions
|
@ -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(
|
async def test_device_remove_devices(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_ws_client: WebSocketGenerator,
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
@ -411,20 +397,13 @@ async def test_device_remove_devices(
|
||||||
entity = entity_registry.entities["lock.a6697750d607098bae8d6baa11ef8063_name"]
|
entity = entity_registry.entities["lock.a6697750d607098bae8d6baa11ef8063_name"]
|
||||||
|
|
||||||
device_entry = device_registry.async_get(entity.device_id)
|
device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(
|
response = await client.remove_device(device_entry.id, config_entry.entry_id)
|
||||||
await hass_ws_client(hass), device_entry.id, config_entry.entry_id
|
assert not response["success"]
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={(DOMAIN, "remove-device-id")},
|
identifiers={(DOMAIN, "remove-device-id")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, config_entry.entry_id)
|
||||||
await remove_device(
|
assert response["success"]
|
||||||
await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id
|
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
|
@ -19,20 +19,6 @@ from homeassistant.util import utcnow
|
||||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
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):
|
def ceiling_fan_with_breeze(name: str):
|
||||||
"""Create a ceiling fan with given name with breeze support."""
|
"""Create a ceiling fan with given name with breeze support."""
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -24,7 +24,6 @@ from .common import (
|
||||||
patch_bond_version,
|
patch_bond_version,
|
||||||
patch_setup_entry,
|
patch_setup_entry,
|
||||||
patch_start_bpup,
|
patch_start_bpup,
|
||||||
remove_device,
|
|
||||||
setup_bond_entity,
|
setup_bond_entity,
|
||||||
setup_platform,
|
setup_platform,
|
||||||
)
|
)
|
||||||
|
@ -318,45 +317,30 @@ async def test_device_remove_devices(
|
||||||
assert entity.unique_id == "test-hub-id_test-device-id"
|
assert entity.unique_id == "test-hub-id_test-device-id"
|
||||||
|
|
||||||
device_entry = device_registry.async_get(entity.device_id)
|
device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(
|
response = await client.remove_device(device_entry.id, config_entry.entry_id)
|
||||||
await hass_ws_client(hass), device_entry.id, config_entry.entry_id
|
assert not response["success"]
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={(DOMAIN, "test-hub-id", "remove-device-id")},
|
identifiers={(DOMAIN, "test-hub-id", "remove-device-id")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, config_entry.entry_id)
|
||||||
await remove_device(
|
assert response["success"]
|
||||||
await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id
|
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={(DOMAIN, "wrong-hub-id", "test-device-id")},
|
identifiers={(DOMAIN, "wrong-hub-id", "test-device-id")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, config_entry.entry_id)
|
||||||
await remove_device(
|
assert response["success"]
|
||||||
await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id
|
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
||||||
hub_device_entry = device_registry.async_get_or_create(
|
hub_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={(DOMAIN, "test-hub-id")},
|
identifiers={(DOMAIN, "test-hub-id")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(hub_device_entry.id, config_entry.entry_id)
|
||||||
await remove_device(
|
assert not response["success"]
|
||||||
await hass_ws_client(hass), hub_device_entry.id, config_entry.entry_id
|
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_smart_by_bond_v3_firmware(hass: HomeAssistant) -> None:
|
async def test_smart_by_bond_v3_firmware(hass: HomeAssistant) -> None:
|
||||||
|
|
|
@ -126,17 +126,3 @@ async def enable_all_entities(hass, freezer, config_entry_id, time_till_next_upd
|
||||||
freezer.tick(time_till_next_update)
|
freezer.tick(time_till_next_update)
|
||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
await hass.async_block_till_done()
|
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"]
|
|
||||||
|
|
|
@ -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.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util
|
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.common import async_fire_time_changed
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
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")})
|
inverter_1 = device_registry.async_get_device(identifiers={(DOMAIN, "12345678")})
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(
|
response = await client.remove_device(inverter_1.id, config_entry.entry_id)
|
||||||
await hass_ws_client(hass), inverter_1.id, config_entry.entry_id
|
assert response["success"]
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
||||||
assert not device_registry.async_get_device(identifiers={(DOMAIN, "12345678")})
|
assert not device_registry.async_get_device(identifiers={(DOMAIN, "12345678")})
|
||||||
|
|
|
@ -399,20 +399,6 @@ async def assert_devices_and_entities_created(
|
||||||
assert root_device.via_device_id is None
|
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():
|
def get_next_aid():
|
||||||
"""Get next aid."""
|
"""Get next aid."""
|
||||||
return model_mixin.id_counter + 1
|
return model_mixin.id_counter + 1
|
||||||
|
|
|
@ -23,7 +23,6 @@ from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
Helper,
|
Helper,
|
||||||
remove_device,
|
|
||||||
setup_accessories_from_file,
|
setup_accessories_from_file,
|
||||||
setup_test_accessories,
|
setup_test_accessories,
|
||||||
setup_test_accessories_with_controller,
|
setup_test_accessories_with_controller,
|
||||||
|
@ -99,19 +98,16 @@ async def test_device_remove_devices(
|
||||||
entity = entity_registry.entities[ALIVE_DEVICE_ENTITY_ID]
|
entity = entity_registry.entities[ALIVE_DEVICE_ENTITY_ID]
|
||||||
|
|
||||||
live_device_entry = device_registry.async_get(entity.device_id)
|
live_device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(await hass_ws_client(hass), live_device_entry.id, entry_id)
|
response = await client.remove_device(live_device_entry.id, entry_id)
|
||||||
is False
|
assert not response["success"]
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={("homekit_controller:accessory-id", "E9:88:E7:B8:B4:40:aid:1")},
|
identifiers={("homekit_controller:accessory-id", "E9:88:E7:B8:B4:40:aid:1")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, entry_id)
|
||||||
await remove_device(await hass_ws_client(hass), dead_device_entry.id, entry_id)
|
assert response["success"]
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_offline_device_raises(hass: HomeAssistant, controller) -> None:
|
async def test_offline_device_raises(hass: HomeAssistant, controller) -> None:
|
||||||
|
|
|
@ -19,20 +19,6 @@ def mock_bluetooth(enable_bluetooth):
|
||||||
"""Auto mock 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(
|
async def test_device_remove_devices(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
|
@ -58,17 +44,13 @@ async def test_device_remove_devices(
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(await hass_ws_client(hass), device_entry.id, entry.entry_id)
|
response = await client.remove_device(device_entry.id, entry.entry_id)
|
||||||
is False
|
assert not response["success"]
|
||||||
)
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
identifiers={(DOMAIN, "not_seen")},
|
identifiers={(DOMAIN, "not_seen")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, entry.entry_id)
|
||||||
await remove_device(
|
assert response["success"]
|
||||||
await hass_ws_client(hass), dead_device_entry.id, entry.entry_id
|
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
|
@ -11,23 +11,7 @@ from homeassistant.setup import async_setup_component
|
||||||
from . import async_load_json_fixture
|
from . import async_load_json_fixture
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
from tests.typing import MockHAClientWebSocket, WebSocketGenerator
|
from tests.typing import 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"]
|
|
||||||
|
|
||||||
|
|
||||||
async def test_config_entry_not_ready(
|
async def test_config_entry_not_ready(
|
||||||
|
@ -116,19 +100,15 @@ async def test_device_remove_devices(
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(
|
response = await client.remove_device(device_entry.id, mock_config_entry.entry_id)
|
||||||
await hass_ws_client(hass), device_entry.id, mock_config_entry.entry_id
|
assert not response["success"]
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
old_device_entry = device_registry.async_get_or_create(
|
old_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=mock_config_entry.entry_id,
|
config_entry_id=mock_config_entry.entry_id,
|
||||||
identifiers={(DOMAIN, "OLD-DEVICE-UUID")},
|
identifiers={(DOMAIN, "OLD-DEVICE-UUID")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(
|
||||||
await remove_device(
|
old_device_entry.id, mock_config_entry.entry_id
|
||||||
await hass_ws_client(hass), old_device_entry.id, mock_config_entry.entry_id
|
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
)
|
||||||
|
assert response["success"]
|
||||||
|
|
|
@ -144,17 +144,3 @@ FEEDER_ROBOT_DATA = {
|
||||||
}
|
}
|
||||||
|
|
||||||
VACUUM_ENTITY_ID = "vacuum.test_litter_box"
|
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"]
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
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 .conftest import setup_integration
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
@ -87,20 +87,13 @@ async def test_device_remove_devices(
|
||||||
assert entity.unique_id == "LR3C012345-litter_box"
|
assert entity.unique_id == "LR3C012345-litter_box"
|
||||||
|
|
||||||
device_entry = device_registry.async_get(entity.device_id)
|
device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(
|
response = await client.remove_device(device_entry.id, config_entry.entry_id)
|
||||||
await hass_ws_client(hass), device_entry.id, config_entry.entry_id
|
assert not response["success"]
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={(litterrobot.DOMAIN, "test-serial", "remove-serial")},
|
identifiers={(litterrobot.DOMAIN, "test-serial", "remove-serial")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, config_entry.entry_id)
|
||||||
await remove_device(
|
assert response["success"]
|
||||||
await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id
|
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ from tests.common import (
|
||||||
async_get_persistent_notifications,
|
async_get_persistent_notifications,
|
||||||
)
|
)
|
||||||
from tests.components.cloud import mock_cloud
|
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 thermostat mode change to "Max"
|
||||||
FAKE_WEBHOOK = {
|
FAKE_WEBHOOK = {
|
||||||
|
@ -517,22 +517,6 @@ async def test_devices(
|
||||||
assert device_entry == snapshot(name=f"{identifier[0]}-{identifier[1]}")
|
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(
|
async def test_device_remove_devices(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_ws_client: WebSocketGenerator,
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
@ -554,20 +538,13 @@ async def test_device_remove_devices(
|
||||||
entity = entity_registry.async_get(climate_entity_livingroom)
|
entity = entity_registry.async_get(climate_entity_livingroom)
|
||||||
|
|
||||||
device_entry = device_registry.async_get(entity.device_id)
|
device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(
|
response = await client.remove_device(device_entry.id, config_entry.entry_id)
|
||||||
await hass_ws_client(hass), device_entry.id, config_entry.entry_id
|
assert not response["success"]
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={(DOMAIN, "remove-device-id")},
|
identifiers={(DOMAIN, "remove-device-id")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, config_entry.entry_id)
|
||||||
await remove_device(
|
assert response["success"]
|
||||||
await hass_ws_client(hass), dead_device_entry.id, config_entry.entry_id
|
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
|
@ -20,20 +20,6 @@ async def test_setup_retry_client_os_error(hass: HomeAssistant) -> None:
|
||||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
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(
|
async def test_device_remove_devices(
|
||||||
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -47,27 +33,18 @@ async def test_device_remove_devices(
|
||||||
entity = registry.entities["sensor.nick_office_temperature"]
|
entity = registry.entities["sensor.nick_office_temperature"]
|
||||||
|
|
||||||
live_zone_device_entry = device_registry.async_get(entity.device_id)
|
live_zone_device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(
|
response = await client.remove_device(live_zone_device_entry.id, entry_id)
|
||||||
await hass_ws_client(hass), live_zone_device_entry.id, entry_id
|
assert not response["success"]
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
entity = registry.entities["sensor.master_suite_humidity"]
|
entity = registry.entities["sensor.master_suite_humidity"]
|
||||||
live_thermostat_device_entry = device_registry.async_get(entity.device_id)
|
live_thermostat_device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
response = await client.remove_device(live_thermostat_device_entry.id, entry_id)
|
||||||
await remove_device(
|
assert not response["success"]
|
||||||
await hass_ws_client(hass), live_thermostat_device_entry.id, entry_id
|
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={(DOMAIN, "unused")},
|
identifiers={(DOMAIN, "unused")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, entry_id)
|
||||||
await remove_device(await hass_ws_client(hass), dead_device_entry.id, entry_id)
|
assert response["success"]
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import aiohttp
|
|
||||||
from pyownet import protocol
|
from pyownet import protocol
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -19,22 +18,6 @@ from . import setup_owproxy_mock_devices
|
||||||
from tests.typing import WebSocketGenerator
|
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")
|
@pytest.mark.usefixtures("owproxy_with_connerror")
|
||||||
async def test_connect_failure(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
async def test_connect_failure(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||||
"""Test connection failure raises ConfigEntryNotReady."""
|
"""Test connection failure raises ConfigEntryNotReady."""
|
||||||
|
@ -125,12 +108,15 @@ async def test_registry_cleanup(
|
||||||
|
|
||||||
# Try to remove "10.111111111111" - fails as it is live
|
# Try to remove "10.111111111111" - fails as it is live
|
||||||
device = device_registry.async_get_device(identifiers={(DOMAIN, live_id)})
|
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 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
|
assert device_registry.async_get_device(identifiers={(DOMAIN, live_id)}) is not None
|
||||||
|
|
||||||
# Try to remove "28.111111111111" - succeeds as it is dead
|
# Try to remove "28.111111111111" - succeeds as it is dead
|
||||||
device = device_registry.async_get_device(identifiers={(DOMAIN, dead_id)})
|
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 len(dr.async_entries_for_config_entry(device_registry, entry_id)) == 1
|
||||||
assert device_registry.async_get_device(identifiers={(DOMAIN, dead_id)}) is None
|
assert device_registry.async_get_device(identifiers={(DOMAIN, dead_id)}) is None
|
||||||
|
|
|
@ -129,20 +129,6 @@ async def test_unload_entry(hass: HomeAssistant, loaded_entry: MockConfigEntry)
|
||||||
assert loaded_entry.state is ConfigEntryState.NOT_LOADED
|
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(
|
async def test_device_remove_devices(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
loaded_entry: MockConfigEntry,
|
loaded_entry: MockConfigEntry,
|
||||||
|
@ -155,20 +141,13 @@ async def test_device_remove_devices(
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
device_entry = device_registry.async_get(entity.device_id)
|
device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(
|
response = await client.remove_device(device_entry.id, loaded_entry.entry_id)
|
||||||
await hass_ws_client(hass), device_entry.id, loaded_entry.entry_id
|
assert not response["success"]
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=loaded_entry.entry_id,
|
config_entry_id=loaded_entry.entry_id,
|
||||||
identifiers={(DOMAIN, "remove-device-id")},
|
identifiers={(DOMAIN, "remove-device-id")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, loaded_entry.entry_id)
|
||||||
await remove_device(
|
assert response["success"]
|
||||||
await hass_ws_client(hass), dead_device_entry.id, loaded_entry.entry_id
|
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
|
@ -152,20 +152,6 @@ async def test_unload_entry(hass: HomeAssistant, get_data: SensiboData) -> None:
|
||||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
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(
|
async def test_device_remove_devices(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
load_int: ConfigEntry,
|
load_int: ConfigEntry,
|
||||||
|
@ -178,20 +164,13 @@ async def test_device_remove_devices(
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
device_entry = device_registry.async_get(entity.device_id)
|
device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(
|
response = await client.remove_device(device_entry.id, load_int.entry_id)
|
||||||
await hass_ws_client(hass), device_entry.id, load_int.entry_id
|
assert not response["success"]
|
||||||
)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=load_int.entry_id,
|
config_entry_id=load_int.entry_id,
|
||||||
identifiers={(DOMAIN, "remove-device-id")},
|
identifiers={(DOMAIN, "remove-device-id")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, load_int.entry_id)
|
||||||
await remove_device(
|
assert response["success"]
|
||||||
await hass_ws_client(hass), dead_device_entry.id, load_int.entry_id
|
|
||||||
)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||||
|
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
import aiohttp
|
|
||||||
from pyunifiprotect import NotAuthorized, NvrError, ProtectApiClient
|
from pyunifiprotect import NotAuthorized, NvrError, ProtectApiClient
|
||||||
from pyunifiprotect.data import NVR, Bootstrap, CloudAccount, Light
|
from pyunifiprotect.data import NVR, Bootstrap, CloudAccount, Light
|
||||||
|
|
||||||
|
@ -26,22 +25,6 @@ from tests.common import MockConfigEntry
|
||||||
from tests.typing import WebSocketGenerator
|
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:
|
async def test_setup(hass: HomeAssistant, ufp: MockUFPFixture) -> None:
|
||||||
"""Test working setup of unifiprotect entry."""
|
"""Test working setup of unifiprotect entry."""
|
||||||
|
|
||||||
|
@ -275,19 +258,16 @@ async def test_device_remove_devices(
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
|
|
||||||
live_device_entry = device_registry.async_get(entity.device_id)
|
live_device_entry = device_registry.async_get(entity.device_id)
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(await hass_ws_client(hass), live_device_entry.id, entry_id)
|
response = await client.remove_device(live_device_entry.id, entry_id)
|
||||||
is False
|
assert not response["success"]
|
||||||
)
|
|
||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=entry_id,
|
config_entry_id=entry_id,
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, "e9:88:e7:b8:b4:40")},
|
connections={(dr.CONNECTION_NETWORK_MAC, "e9:88:e7:b8:b4:40")},
|
||||||
)
|
)
|
||||||
assert (
|
response = await client.remove_device(dead_device_entry.id, entry_id)
|
||||||
await remove_device(await hass_ws_client(hass), dead_device_entry.id, entry_id)
|
assert response["success"]
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_device_remove_devices_nvr(
|
async def test_device_remove_devices_nvr(
|
||||||
|
@ -306,7 +286,6 @@ async def test_device_remove_devices_nvr(
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
|
|
||||||
live_device_entry = list(device_registry.devices.values())[0]
|
live_device_entry = list(device_registry.devices.values())[0]
|
||||||
assert (
|
client = await hass_ws_client(hass)
|
||||||
await remove_device(await hass_ws_client(hass), live_device_entry.id, entry_id)
|
response = await client.remove_device(live_device_entry.id, entry_id)
|
||||||
is False
|
assert not response["success"]
|
||||||
)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue