Skip to content

Commit

Permalink
Use remove_device helper in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Apr 26, 2024
1 parent 49d8ac0 commit 4edc445
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 171 deletions.
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)

Check failure on line 816 in tests/components/cast/test_media_player.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (cast)

test_device_registry[8009-None] AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'

Check failure on line 816 in tests/components/cast/test_media_player.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (cast)

test_device_registry[12345-None] AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
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)

Check failure on line 86 in tests/components/devolo_home_control/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (devolo_home_control)

test_remove_device AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
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)

Check failure on line 236 in tests/components/fritzbox/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (fritzbox)

test_remove_device AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
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)

Check failure on line 637 in tests/components/matter/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (matter)

test_remove_config_entry_device[True] AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
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)

Check failure on line 666 in tests/components/matter/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (matter)

test_remove_config_entry_device_no_node[True] AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
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(

Check failure on line 277 in tests/components/mqtt/test_device_tracker.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (mqtt)

test_cleanup_device_tracker AttributeError: 'CoalescingResponse' object has no attribute '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(

Check failure on line 989 in tests/components/mqtt/test_device_trigger.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (mqtt)

test_not_fires_on_mqtt_message_after_remove_from_registry AttributeError: 'CoalescingResponse' object has no attribute '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(

Check failure on line 1346 in tests/components/mqtt/test_device_trigger.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (mqtt)

test_cleanup_trigger AttributeError: 'CoalescingResponse' object has no attribute '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(

Check failure on line 846 in tests/components/mqtt/test_discovery.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (mqtt)

test_cleanup_device AttributeError: 'CoalescingResponse' object has no attribute '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(

Check failure on line 982 in tests/components/mqtt/test_discovery.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (mqtt)

test_cleanup_device_multiple_config_entries AttributeError: 'CoalescingResponse' object has no attribute '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)

Check failure on line 2853 in tests/components/mqtt/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (mqtt)

test_mqtt_ws_remove_discovered_device AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
assert response["success"]

# Verify device entry is cleared
Expand Down
19 changes: 3 additions & 16 deletions tests/components/mqtt/test_tag.py
Expand Up @@ -419,14 +419,7 @@ 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,
}
)
await ws_client.remove_device(device_entry.id, mqtt_config_entry.entry_id)

Check failure on line 422 in tests/components/mqtt/test_tag.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (mqtt)

test_not_fires_on_mqtt_message_after_remove_from_registry AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
response = await ws_client.receive_json()
assert response["success"]
tag_mock.reset_mock()
Expand Down Expand Up @@ -612,15 +605,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(

Check failure on line 608 in tests/components/mqtt/test_tag.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (mqtt)

test_cleanup_tag AttributeError: 'CoalescingResponse' object has no attribute '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)

Check failure on line 44 in tests/components/mysensors/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (mysensors)

test_remove_config_entry_device AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
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)

Check failure on line 115 in tests/components/rfxtrx/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (rfxtrx)

test_ws_device_remove AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
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(

Check failure on line 171 in tests/components/tasmota/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (tasmota)

test_tasmota_ws_remove_discovered_device AttributeError: 'CoalescingResponse' object has no attribute '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)

Check failure on line 1368 in tests/components/zwave_js/test_init.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (zwave_js)

test_replace_different_node AttributeError: 'CoalescingResponse' object has no attribute 'remove_device'
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

0 comments on commit 4edc445

Please sign in to comment.