diff --git a/tests/components/tasmota/test_common.py b/tests/components/tasmota/test_common.py index 499e732719c..0480520f469 100644 --- a/tests/components/tasmota/test_common.py +++ b/tests/components/tasmota/test_common.py @@ -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"] diff --git a/tests/components/tasmota/test_device_trigger.py b/tests/components/tasmota/test_device_trigger.py index 8d299a272f7..d4aeab70bf2 100644 --- a/tests/components/tasmota/test_device_trigger.py +++ b/tests/components/tasmota/test_device_trigger.py @@ -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() diff --git a/tests/components/tasmota/test_discovery.py b/tests/components/tasmota/test_discovery.py index 122c22f752e..8dc2c22f1c7 100644 --- a/tests/components/tasmota/test_discovery.py +++ b/tests/components/tasmota/test_discovery.py @@ -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( diff --git a/tests/components/tasmota/test_init.py b/tests/components/tasmota/test_init.py index 72a86fc9986..0123421d5ae 100644 --- a/tests/components/tasmota/test_init.py +++ b/tests/components/tasmota/test_init.py @@ -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(