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

* Use remove_device helper in tests

* Update test_tag.py

* Update test_tag.py
This commit is contained in:
epenet 2024-04-30 12:52:33 +02:00 committed by GitHub
parent a3942e019b
commit ad84ff18eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 29 additions and 171 deletions

View file

@ -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()

View file

@ -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

View file

@ -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()

View file

@ -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()
@ -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()

View file

@ -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()

View file

@ -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()
@ -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()

View file

@ -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()
@ -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()

View file

@ -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

View file

@ -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()
@ -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()

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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"]