Use remove_device helper in tasmota tests (#116617)
This commit is contained in:
parent
1d16e219e4
commit
3a8bdfbfdf
4 changed files with 18 additions and 22 deletions
|
@ -22,9 +22,11 @@ from hatasmota.utils import (
|
||||||
|
|
||||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX, DOMAIN
|
from homeassistant.components.tasmota.const import DEFAULT_PREFIX, DOMAIN
|
||||||
from homeassistant.const import STATE_UNAVAILABLE
|
from homeassistant.const import STATE_UNAVAILABLE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
|
|
||||||
from tests.common import async_fire_mqtt_message
|
from tests.common import async_fire_mqtt_message
|
||||||
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
"ip": "192.168.15.10",
|
"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."""
|
"""Remove config entry from a device."""
|
||||||
if config_entry_id is None:
|
if config_entry_id is None:
|
||||||
config_entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id
|
config_entry_id = hass.config_entries.async_entries(DOMAIN)[0].entry_id
|
||||||
await ws_client.send_json(
|
ws_client = await hass_ws_client(hass)
|
||||||
{
|
response = await ws_client.remove_device(device_id, config_entry_id)
|
||||||
"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"]
|
assert response["success"]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -849,7 +849,7 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
# Remove the device
|
# 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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
async_fire_mqtt_message(
|
async_fire_mqtt_message(
|
||||||
|
@ -1139,7 +1139,7 @@ async def test_attach_unknown_remove_device_from_registry(
|
||||||
)
|
)
|
||||||
|
|
||||||
# Remove the device
|
# 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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -446,7 +446,7 @@ async def test_device_remove_stale(
|
||||||
assert device_entry is not None
|
assert device_entry is not None
|
||||||
|
|
||||||
# Remove the device
|
# 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
|
# Verify device entry is removed
|
||||||
device_entry = device_reg.async_get_device(
|
device_entry = device_reg.async_get_device(
|
||||||
|
|
|
@ -49,7 +49,7 @@ async def test_device_remove(
|
||||||
)
|
)
|
||||||
assert device_entry is not None
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Verify device entry is removed
|
# Verify device entry is removed
|
||||||
|
@ -98,9 +98,7 @@ async def test_device_remove_non_tasmota_device(
|
||||||
)
|
)
|
||||||
assert device_entry is not None
|
assert device_entry is not None
|
||||||
|
|
||||||
await remove_device(
|
await remove_device(hass, hass_ws_client, device_entry.id, config_entry.entry_id)
|
||||||
hass, await hass_ws_client(hass), device_entry.id, config_entry.entry_id
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Verify device entry is removed
|
# Verify device entry is removed
|
||||||
|
@ -131,7 +129,7 @@ async def test_device_remove_stale_tasmota_device(
|
||||||
)
|
)
|
||||||
assert device_entry is not None
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Verify device entry is removed
|
# Verify device entry is removed
|
||||||
|
@ -166,12 +164,10 @@ async def test_tasmota_ws_remove_discovered_device(
|
||||||
)
|
)
|
||||||
assert device_entry is not None
|
assert device_entry is not None
|
||||||
|
|
||||||
client = await hass_ws_client(hass)
|
|
||||||
tasmota_config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
tasmota_config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||||
response = await client.remove_device(
|
await remove_device(
|
||||||
device_entry.id, tasmota_config_entry.entry_id
|
hass, hass_ws_client, device_entry.id, tasmota_config_entry.entry_id
|
||||||
)
|
)
|
||||||
assert response["success"]
|
|
||||||
|
|
||||||
# Verify device entry is cleared
|
# Verify device entry is cleared
|
||||||
device_entry = device_reg.async_get_device(
|
device_entry = device_reg.async_get_device(
|
||||||
|
|
Loading…
Add table
Reference in a new issue