core/tests/components/upnp/test_init.py

54 lines
1.7 KiB
Python
Raw Normal View History

2018-09-17 20:08:09 +00:00
"""Test UPnP/IGD setup process."""
2018-08-29 19:19:04 +00:00
2018-09-17 20:08:09 +00:00
from homeassistant.components import upnp
from homeassistant.components.upnp.const import (
DISCOVERY_LOCATION,
DISCOVERY_ST,
DISCOVERY_UDN,
)
2018-09-17 20:08:09 +00:00
from homeassistant.components.upnp.device import Device
2018-08-29 19:19:04 +00:00
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.setup import async_setup_component
2018-08-29 19:19:04 +00:00
from .mock_device import MockDevice
2018-08-29 19:19:04 +00:00
from tests.async_mock import AsyncMock, patch
from tests.common import MockConfigEntry
2018-09-07 22:11:23 +00:00
2018-08-30 14:38:43 +00:00
async def test_async_setup_entry_default(hass):
2018-08-29 19:19:04 +00:00
"""Test async_setup_entry."""
2019-07-31 19:25:30 +00:00
udn = "uuid:device_1"
mock_device = MockDevice(udn)
discovery_infos = [
{
DISCOVERY_UDN: mock_device.udn,
DISCOVERY_ST: mock_device.device_type,
DISCOVERY_LOCATION: "http://192.168.1.1/desc.xml",
}
]
entry = MockConfigEntry(
domain=upnp.DOMAIN, data={"udn": mock_device.udn, "st": mock_device.device_type}
)
2018-08-30 14:38:43 +00:00
config = {
# no upnp
}
async_discover = AsyncMock(return_value=[])
with patch.object(
Device, "async_create_device", AsyncMock(return_value=mock_device)
), patch.object(Device, "async_discover", async_discover):
# initialisation of component, no device discovered
2019-07-31 19:25:30 +00:00
await async_setup_component(hass, "upnp", config)
await hass.async_block_till_done()
2018-08-29 19:19:04 +00:00
# loading of config_entry, device discovered
async_discover.return_value = discovery_infos
assert await upnp.async_setup_entry(hass, entry) is True
2018-08-30 14:38:43 +00:00
# ensure device is stored/used
2019-07-31 19:25:30 +00:00
assert hass.data[upnp.DOMAIN]["devices"][udn] == mock_device
2018-08-30 14:38:43 +00:00
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
await hass.async_block_till_done()