Use remove_device helper in tasmota tests (#116617)

pull/117691/head
epenet 2024-05-18 13:43:21 +02:00 committed by GitHub
parent 1d16e219e4
commit 3a8bdfbfdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 22 deletions

View File

@ -22,9 +22,11 @@ from hatasmota.utils import (
from homeassistant.components.tasmota.const import DEFAULT_PREFIX, DOMAIN
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
from tests.common import async_fire_mqtt_message
from tests.typing import WebSocketGenerator
DEFAULT_CONFIG = {
"ip": "192.168.15.10",
@ -108,19 +110,17 @@ DEFAULT_SENSOR_CONFIG = {
}
async def remove_device(hass, ws_client, device_id, config_entry_id=None):
async def remove_device(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_id: str,
config_entry_id: str | None = None,
) -> None:
"""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()
ws_client = await hass_ws_client(hass)
response = await ws_client.remove_device(device_id, config_entry_id)
assert response["success"]

View File

@ -849,7 +849,7 @@ 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)
await remove_device(hass, hass_ws_client, device_entry.id)
await hass.async_block_till_done()
async_fire_mqtt_message(
@ -1139,7 +1139,7 @@ async def test_attach_unknown_remove_device_from_registry(
)
# Remove the device
await remove_device(hass, await hass_ws_client(hass), device_entry.id)
await remove_device(hass, hass_ws_client, device_entry.id)
await hass.async_block_till_done()

View File

@ -446,7 +446,7 @@ 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)
await remove_device(hass, hass_ws_client, device_entry.id)
# Verify device entry is removed
device_entry = device_reg.async_get_device(

View File

@ -49,7 +49,7 @@ async def test_device_remove(
)
assert device_entry is not None
await remove_device(hass, await hass_ws_client(hass), device_entry.id)
await remove_device(hass, hass_ws_client, device_entry.id)
await hass.async_block_till_done()
# Verify device entry is removed
@ -98,9 +98,7 @@ async def test_device_remove_non_tasmota_device(
)
assert device_entry is not None
await remove_device(
hass, await hass_ws_client(hass), device_entry.id, config_entry.entry_id
)
await remove_device(hass, hass_ws_client, device_entry.id, config_entry.entry_id)
await hass.async_block_till_done()
# Verify device entry is removed
@ -131,7 +129,7 @@ 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)
await remove_device(hass, hass_ws_client, device_entry.id)
await hass.async_block_till_done()
# Verify device entry is removed
@ -166,12 +164,10 @@ async def test_tasmota_ws_remove_discovered_device(
)
assert device_entry is not None
client = await hass_ws_client(hass)
tasmota_config_entry = hass.config_entries.async_entries(DOMAIN)[0]
response = await client.remove_device(
device_entry.id, tasmota_config_entry.entry_id
await remove_device(
hass, hass_ws_client, device_entry.id, tasmota_config_entry.entry_id
)
assert response["success"]
# Verify device entry is cleared
device_entry = device_reg.async_get_device(