Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use remove_device helper in tests (1/2) #116240

Merged
merged 3 commits into from Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions tests/components/cast/test_media_player.py
Expand Up @@ -813,15 +813,7 @@ async def test_device_registry(
chromecast.disconnect.assert_not_called()

client = await hass_ws_client(hass)
await client.send_json(
{
"id": 5,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": cast_entry.entry_id,
"device_id": device_entry.id,
}
)
response = await client.receive_json()
response = await client.remove_device(device_entry.id, cast_entry.entry_id)
assert response["success"]

await hass.async_block_till_done()
Expand Down
10 changes: 1 addition & 9 deletions tests/components/devolo_home_control/test_init.py
Expand Up @@ -83,15 +83,7 @@ async def test_remove_device(
assert device_entry

client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": entry.entry_id,
"device_id": device_entry.id,
}
)
response = await client.receive_json()
response = await client.remove_device(device_entry.id, entry.entry_id)
assert response["success"]
assert device_registry.async_get_device(identifiers={(DOMAIN, "Test")}) is None
assert hass.states.get(f"{BINARY_SENSOR_DOMAIN}.test") is None
20 changes: 2 additions & 18 deletions tests/components/fritzbox/test_init.py
Expand Up @@ -233,30 +233,14 @@ async def test_remove_device(

# try to delete good_device
ws_client = await hass_ws_client(hass)
await ws_client.send_json(
{
"id": 5,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": entry.entry_id,
"device_id": good_device.id,
}
)
response = await ws_client.receive_json()
response = await ws_client.remove_device(good_device.id, entry.entry_id)
assert not response["success"]
assert response["error"]["code"] == "home_assistant_error"
await hass.async_block_till_done()

# try to delete orphan_device
ws_client = await hass_ws_client(hass)
await ws_client.send_json(
{
"id": 5,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": entry.entry_id,
"device_id": orphan_device.id,
}
)
response = await ws_client.receive_json()
response = await ws_client.remove_device(orphan_device.id, entry.entry_id)
assert response["success"]
await hass.async_block_till_done()

Expand Down
20 changes: 2 additions & 18 deletions tests/components/matter/test_init.py
Expand Up @@ -634,15 +634,7 @@ async def test_remove_config_entry_device(
assert hass.states.get(entity_id)

client = await hass_ws_client(hass)
await client.send_json(
{
"id": 5,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": config_entry.entry_id,
"device_id": device_entry.id,
}
)
response = await client.receive_json()
response = await client.remove_device(device_entry.id, config_entry.entry_id)
assert response["success"]
await hass.async_block_till_done()

Expand Down Expand Up @@ -671,15 +663,7 @@ async def test_remove_config_entry_device_no_node(
)

client = await hass_ws_client(hass)
await client.send_json(
{
"id": 5,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": config_entry.entry_id,
"device_id": device_entry.id,
}
)
response = await client.receive_json()
response = await client.remove_device(device_entry.id, config_entry.entry_id)
assert response["success"]
await hass.async_block_till_done()

Expand Down
10 changes: 2 additions & 8 deletions tests/components/mqtt/test_device_tracker.py
Expand Up @@ -274,15 +274,9 @@ async def test_cleanup_device_tracker(

# Remove MQTT from the device
mqtt_config_entry = hass.config_entries.async_entries(MQTT_DOMAIN)[0]
await ws_client.send_json(
{
"id": 6,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": mqtt_config_entry.entry_id,
"device_id": device_entry.id,
}
response = await ws_client.remove_device(
device_entry.id, mqtt_config_entry.entry_id
)
response = await ws_client.receive_json()
assert response["success"]
await hass.async_block_till_done()
await hass.async_block_till_done()
Expand Down
20 changes: 4 additions & 16 deletions tests/components/mqtt/test_device_trigger.py
Expand Up @@ -986,15 +986,9 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(

# Remove MQTT from the device
mqtt_config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await ws_client.send_json(
{
"id": 6,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": mqtt_config_entry.entry_id,
"device_id": device_entry.id,
}
response = await ws_client.remove_device(
device_entry.id, mqtt_config_entry.entry_id
)
response = await ws_client.receive_json()
assert response["success"]
await hass.async_block_till_done()

Expand Down Expand Up @@ -1349,15 +1343,9 @@ async def test_cleanup_trigger(

# Remove MQTT from the device
mqtt_config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await ws_client.send_json(
{
"id": 6,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": mqtt_config_entry.entry_id,
"device_id": device_entry.id,
}
response = await ws_client.remove_device(
device_entry.id, mqtt_config_entry.entry_id
)
response = await ws_client.receive_json()
assert response["success"]
await hass.async_block_till_done()
await hass.async_block_till_done()
Expand Down
20 changes: 4 additions & 16 deletions tests/components/mqtt/test_discovery.py
Expand Up @@ -843,15 +843,9 @@ async def test_cleanup_device(

# Remove MQTT from the device
mqtt_config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
await ws_client.send_json(
{
"id": 6,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": mqtt_config_entry.entry_id,
"device_id": device_entry.id,
}
response = await ws_client.remove_device(
device_entry.id, mqtt_config_entry.entry_id
)
response = await ws_client.receive_json()
assert response["success"]
await hass.async_block_till_done()
await hass.async_block_till_done()
Expand Down Expand Up @@ -985,15 +979,9 @@ async def test_cleanup_device_multiple_config_entries(

# Remove MQTT from the device
mqtt_config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
await ws_client.send_json(
{
"id": 6,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": mqtt_config_entry.entry_id,
"device_id": device_entry.id,
}
response = await ws_client.remove_device(
device_entry.id, mqtt_config_entry.entry_id
)
response = await ws_client.receive_json()
assert response["success"]

await hass.async_block_till_done()
Expand Down
10 changes: 1 addition & 9 deletions tests/components/mqtt/test_init.py
Expand Up @@ -2850,15 +2850,7 @@ async def test_mqtt_ws_remove_discovered_device(

client = await hass_ws_client(hass)
mqtt_config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
await client.send_json(
{
"id": 5,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": mqtt_config_entry.entry_id,
"device_id": device_entry.id,
}
)
response = await client.receive_json()
response = await client.remove_device(device_entry.id, mqtt_config_entry.entry_id)
assert response["success"]

# Verify device entry is cleared
Expand Down
20 changes: 4 additions & 16 deletions tests/components/mqtt/test_tag.py
Expand Up @@ -419,15 +419,9 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(

# Remove MQTT from the device
mqtt_config_entry = hass.config_entries.async_entries(MQTT_DOMAIN)[0]
await ws_client.send_json(
{
"id": 6,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": mqtt_config_entry.entry_id,
"device_id": device_entry.id,
}
response = await ws_client.remove_device(
device_entry.id, mqtt_config_entry.entry_id
)
response = await ws_client.receive_json()
assert response["success"]
tag_mock.reset_mock()

Expand Down Expand Up @@ -612,15 +606,9 @@ async def test_cleanup_tag(

# Remove MQTT from the device
mqtt_config_entry = hass.config_entries.async_entries(MQTT_DOMAIN)[0]
await ws_client.send_json(
{
"id": 6,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": mqtt_config_entry.entry_id,
"device_id": device_entry1.id,
}
response = await ws_client.remove_device(
device_entry1.id, mqtt_config_entry.entry_id
)
response = await ws_client.receive_json()
assert response["success"]
await hass.async_block_till_done()
await hass.async_block_till_done()
Expand Down
10 changes: 1 addition & 9 deletions tests/components/mysensors/test_init.py
Expand Up @@ -41,15 +41,7 @@ async def test_remove_config_entry_device(
assert state

client = await hass_ws_client(hass)
await client.send_json(
{
"id": 5,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": config_entry.entry_id,
"device_id": device_entry.id,
}
)
response = await client.receive_json()
response = await client.remove_device(device_entry.id, config_entry.entry_id)
assert response["success"]
await hass.async_block_till_done()

Expand Down
10 changes: 1 addition & 9 deletions tests/components/rfxtrx/test_init.py
Expand Up @@ -112,15 +112,7 @@ async def test_ws_device_remove(

# Ask to remove existing device
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 5,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": mock_entry.entry_id,
"device_id": device_entry.id,
}
)
response = await client.receive_json()
response = await client.remove_device(device_entry.id, mock_entry.entry_id)
assert response["success"]

# Verify device entry is removed
Expand Down
10 changes: 2 additions & 8 deletions tests/components/tasmota/test_init.py
Expand Up @@ -168,15 +168,9 @@ async def test_tasmota_ws_remove_discovered_device(

client = await hass_ws_client(hass)
tasmota_config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await client.send_json(
{
"id": 5,
"config_entry_id": tasmota_config_entry.entry_id,
"type": "config/device_registry/remove_config_entry",
"device_id": device_entry.id,
}
response = await client.remove_device(
device_entry.id, tasmota_config_entry.entry_id
)
response = await client.receive_json()
assert response["success"]

# Verify device entry is cleared
Expand Down
30 changes: 4 additions & 26 deletions tests/components/zwave_js/test_init.py
Expand Up @@ -1365,40 +1365,18 @@ async def test_replace_different_node(
driver = client.driver
client.driver = None

await ws_client.send_json(
{
"id": 1,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": integration.entry_id,
"device_id": hank_device.id,
}
)
response = await ws_client.receive_json()
response = await ws_client.remove_device(hank_device.id, integration.entry_id)
assert not response["success"]

client.driver = driver

# Attempting to remove the hank device should pass, but removing the multisensor should not
await ws_client.send_json(
{
"id": 2,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": integration.entry_id,
"device_id": hank_device.id,
}
)
response = await ws_client.receive_json()
response = await ws_client.remove_device(hank_device.id, integration.entry_id)
assert response["success"]

await ws_client.send_json(
{
"id": 3,
"type": "config/device_registry/remove_config_entry",
"config_entry_id": integration.entry_id,
"device_id": multisensor_6_device.id,
}
response = await ws_client.remove_device(
multisensor_6_device.id, integration.entry_id
)
response = await ws_client.receive_json()
assert not response["success"]


Expand Down