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 tasmota tests #116443

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 1 addition & 17 deletions tests/components/tasmota/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
get_topic_tele_will,
)

from homeassistant.components.tasmota.const import DEFAULT_PREFIX, DOMAIN
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er

Expand Down Expand Up @@ -108,22 +108,6 @@
}


async def remove_device(hass, ws_client, device_id, config_entry_id=None):
Copy link
Contributor Author

@epenet epenet Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt it was better to remove this helper method completely, to align with #116240 and #116442

Another possibility is to adjust only this function and have:

    if config_entry_id is None:
        config_entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id
    response = await ws_client.remove_device(device_id, config_entry_id)
    assert response["success"]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative created in #116617

"""Remove config entry from a device."""
if config_entry_id is None:
config_entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id
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()
assert response["success"]


async def help_test_availability_when_connection_lost(
hass,
mqtt_client_mock,
Expand Down
10 changes: 7 additions & 3 deletions tests/components/tasmota/test_device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from homeassistant.helpers.trigger import async_initialize_triggers
from homeassistant.setup import async_setup_component

from .test_common import DEFAULT_CONFIG, remove_device
from .test_common import DEFAULT_CONFIG

from tests.common import async_fire_mqtt_message, async_get_device_automations
from tests.typing import MqttMockHAClient, WebSocketGenerator
Expand Down Expand Up @@ -849,7 +849,9 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
assert len(calls) == 1

# Remove the device
await remove_device(hass, await hass_ws_client(hass), device_entry.id)
config_entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id
client = await hass_ws_client(hass)
await client.remove_device(device_entry.id, config_entry_id)
await hass.async_block_till_done()

async_fire_mqtt_message(
Expand Down Expand Up @@ -1139,7 +1141,9 @@ async def test_attach_unknown_remove_device_from_registry(
)

# Remove the device
await remove_device(hass, await hass_ws_client(hass), device_entry.id)
config_entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id
client = await hass_ws_client(hass)
await client.remove_device(device_entry.id, config_entry_id)
await hass.async_block_till_done()


Expand Down
8 changes: 5 additions & 3 deletions tests/components/tasmota/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from homeassistant.components.tasmota.const import DEFAULT_PREFIX
from homeassistant.components.tasmota.const import DEFAULT_PREFIX, DOMAIN
from homeassistant.components.tasmota.discovery import ALREADY_DISCOVERED
from homeassistant.core import HomeAssistant
from homeassistant.helpers import (
Expand All @@ -17,7 +17,7 @@
from homeassistant.setup import async_setup_component

from .conftest import setup_tasmota_helper
from .test_common import DEFAULT_CONFIG, DEFAULT_CONFIG_9_0_0_3, remove_device
from .test_common import DEFAULT_CONFIG, DEFAULT_CONFIG_9_0_0_3

from tests.common import MockConfigEntry, async_fire_mqtt_message
from tests.typing import MqttMockHAClient, WebSocketGenerator
Expand Down Expand Up @@ -446,7 +446,9 @@ async def test_device_remove_stale(
assert device_entry is not None

# Remove the device
await remove_device(hass, await hass_ws_client(hass), device_entry.id)
config_entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id
client = await hass_ws_client(hass)
await client.remove_device(device_entry.id, config_entry_id)

# Verify device entry is removed
device_entry = device_reg.async_get_device(
Expand Down
15 changes: 9 additions & 6 deletions tests/components/tasmota/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component

from .test_common import DEFAULT_CONFIG, DEFAULT_SENSOR_CONFIG, remove_device
from .test_common import DEFAULT_CONFIG, DEFAULT_SENSOR_CONFIG

from tests.common import (
MockConfigEntry,
Expand Down Expand Up @@ -49,7 +49,9 @@ async def test_device_remove(
)
assert device_entry is not None

await remove_device(hass, await hass_ws_client(hass), device_entry.id)
config_entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id
client = await hass_ws_client(hass)
await client.remove_device(device_entry.id, config_entry_id)
await hass.async_block_till_done()

# Verify device entry is removed
Expand Down Expand Up @@ -98,9 +100,8 @@ async def async_remove_config_entry_device(hass, config_entry, device_entry):
)
assert device_entry is not None

await remove_device(
hass, await hass_ws_client(hass), device_entry.id, config_entry.entry_id
)
client = await hass_ws_client(hass)
await client.remove_device(device_entry.id, config_entry.entry_id)
await hass.async_block_till_done()

# Verify device entry is removed
Expand Down Expand Up @@ -131,7 +132,9 @@ async def test_device_remove_stale_tasmota_device(
)
assert device_entry is not None

await remove_device(hass, await hass_ws_client(hass), device_entry.id)
config_entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id
client = await hass_ws_client(hass)
await client.remove_device(device_entry.id, config_entry_id)
await hass.async_block_till_done()

# Verify device entry is removed
Expand Down