diff --git a/tests/components/upnp/test_init.py b/tests/components/upnp/test_init.py index 3f7c64ab3ad..26b2f970fed 100644 --- a/tests/components/upnp/test_init.py +++ b/tests/components/upnp/test_init.py @@ -2,7 +2,6 @@ from unittest.mock import AsyncMock, patch -from homeassistant.components import upnp from homeassistant.components.upnp.const import ( CONFIG_ENTRY_ST, CONFIG_ENTRY_UDN, @@ -13,10 +12,9 @@ from homeassistant.components.upnp.const import ( DISCOVERY_UNIQUE_ID, DISCOVERY_USN, DOMAIN, - DOMAIN_DEVICES, ) from homeassistant.components.upnp.device import Device -from homeassistant.const import EVENT_HOMEASSISTANT_STOP +from homeassistant.helpers.typing import HomeAssistantType from homeassistant.setup import async_setup_component from .mock_device import MockDevice @@ -24,7 +22,7 @@ from .mock_device import MockDevice from tests.common import MockConfigEntry -async def test_async_setup_entry_default(hass): +async def test_async_setup_entry_default(hass: HomeAssistantType): """Test async_setup_entry.""" udn = "uuid:device_1" location = "http://192.168.1.1/desc.xml" @@ -40,7 +38,7 @@ async def test_async_setup_entry_default(hass): } ] entry = MockConfigEntry( - domain=upnp.DOMAIN, + domain=DOMAIN, data={ CONFIG_ENTRY_UDN: mock_device.udn, CONFIG_ENTRY_ST: mock_device.device_type, @@ -50,10 +48,11 @@ async def test_async_setup_entry_default(hass): config = { # no upnp } + async_create_device = AsyncMock(return_value=mock_device) async_discover = AsyncMock() - with patch.object( - Device, "async_create_device", AsyncMock(return_value=mock_device) - ), patch.object(Device, "async_discover", async_discover): + with patch.object(Device, "async_create_device", async_create_device), patch.object( + Device, "async_discover", async_discover + ): # initialisation of component, no device discovered async_discover.return_value = [] await async_setup_component(hass, "upnp", config) @@ -61,16 +60,14 @@ async def test_async_setup_entry_default(hass): # loading of config_entry, device discovered async_discover.return_value = discoveries - assert await upnp.async_setup_entry(hass, entry) is True + entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(entry.entry_id) is True # ensure device is stored/used - assert hass.data[DOMAIN][DOMAIN_DEVICES][udn] == mock_device - - hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) - await hass.async_block_till_done() + async_create_device.assert_called_with(hass, discoveries[0][DISCOVERY_LOCATION]) -async def test_sync_setup_entry_multiple_discoveries(hass): +async def test_sync_setup_entry_multiple_discoveries(hass: HomeAssistantType): """Test async_setup_entry.""" udn_0 = "uuid:device_1" location_0 = "http://192.168.1.1/desc.xml" @@ -97,7 +94,7 @@ async def test_sync_setup_entry_multiple_discoveries(hass): }, ] entry = MockConfigEntry( - domain=upnp.DOMAIN, + domain=DOMAIN, data={ CONFIG_ENTRY_UDN: mock_device_1.udn, CONFIG_ENTRY_ST: mock_device_1.device_type, @@ -119,12 +116,8 @@ async def test_sync_setup_entry_multiple_discoveries(hass): # loading of config_entry, device discovered async_discover.return_value = discoveries - assert await upnp.async_setup_entry(hass, entry) is True + entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(entry.entry_id) is True # ensure device is stored/used async_create_device.assert_called_with(hass, discoveries[1][DISCOVERY_LOCATION]) - assert udn_0 not in hass.data[DOMAIN][DOMAIN_DEVICES] - assert hass.data[DOMAIN][DOMAIN_DEVICES][udn_1] == mock_device_1 - - hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP) - await hass.async_block_till_done()