mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Address late review comments for upnp (#45696)
This commit is contained in:
parent
ba55f1ff4b
commit
71c169c84f
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from homeassistant.components import upnp
|
|
||||||
from homeassistant.components.upnp.const import (
|
from homeassistant.components.upnp.const import (
|
||||||
CONFIG_ENTRY_ST,
|
CONFIG_ENTRY_ST,
|
||||||
CONFIG_ENTRY_UDN,
|
CONFIG_ENTRY_UDN,
|
||||||
@ -13,10 +12,9 @@ from homeassistant.components.upnp.const import (
|
|||||||
DISCOVERY_UNIQUE_ID,
|
DISCOVERY_UNIQUE_ID,
|
||||||
DISCOVERY_USN,
|
DISCOVERY_USN,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
DOMAIN_DEVICES,
|
|
||||||
)
|
)
|
||||||
from homeassistant.components.upnp.device import Device
|
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 homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .mock_device import MockDevice
|
from .mock_device import MockDevice
|
||||||
@ -24,7 +22,7 @@ from .mock_device import MockDevice
|
|||||||
from tests.common import MockConfigEntry
|
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."""
|
"""Test async_setup_entry."""
|
||||||
udn = "uuid:device_1"
|
udn = "uuid:device_1"
|
||||||
location = "http://192.168.1.1/desc.xml"
|
location = "http://192.168.1.1/desc.xml"
|
||||||
@ -40,7 +38,7 @@ async def test_async_setup_entry_default(hass):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=upnp.DOMAIN,
|
domain=DOMAIN,
|
||||||
data={
|
data={
|
||||||
CONFIG_ENTRY_UDN: mock_device.udn,
|
CONFIG_ENTRY_UDN: mock_device.udn,
|
||||||
CONFIG_ENTRY_ST: mock_device.device_type,
|
CONFIG_ENTRY_ST: mock_device.device_type,
|
||||||
@ -50,10 +48,11 @@ async def test_async_setup_entry_default(hass):
|
|||||||
config = {
|
config = {
|
||||||
# no upnp
|
# no upnp
|
||||||
}
|
}
|
||||||
|
async_create_device = AsyncMock(return_value=mock_device)
|
||||||
async_discover = AsyncMock()
|
async_discover = AsyncMock()
|
||||||
with patch.object(
|
with patch.object(Device, "async_create_device", async_create_device), patch.object(
|
||||||
Device, "async_create_device", AsyncMock(return_value=mock_device)
|
Device, "async_discover", async_discover
|
||||||
), patch.object(Device, "async_discover", async_discover):
|
):
|
||||||
# initialisation of component, no device discovered
|
# initialisation of component, no device discovered
|
||||||
async_discover.return_value = []
|
async_discover.return_value = []
|
||||||
await async_setup_component(hass, "upnp", config)
|
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
|
# loading of config_entry, device discovered
|
||||||
async_discover.return_value = discoveries
|
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
|
# ensure device is stored/used
|
||||||
assert hass.data[DOMAIN][DOMAIN_DEVICES][udn] == mock_device
|
async_create_device.assert_called_with(hass, discoveries[0][DISCOVERY_LOCATION])
|
||||||
|
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_sync_setup_entry_multiple_discoveries(hass):
|
async def test_sync_setup_entry_multiple_discoveries(hass: HomeAssistantType):
|
||||||
"""Test async_setup_entry."""
|
"""Test async_setup_entry."""
|
||||||
udn_0 = "uuid:device_1"
|
udn_0 = "uuid:device_1"
|
||||||
location_0 = "http://192.168.1.1/desc.xml"
|
location_0 = "http://192.168.1.1/desc.xml"
|
||||||
@ -97,7 +94,7 @@ async def test_sync_setup_entry_multiple_discoveries(hass):
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=upnp.DOMAIN,
|
domain=DOMAIN,
|
||||||
data={
|
data={
|
||||||
CONFIG_ENTRY_UDN: mock_device_1.udn,
|
CONFIG_ENTRY_UDN: mock_device_1.udn,
|
||||||
CONFIG_ENTRY_ST: mock_device_1.device_type,
|
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
|
# loading of config_entry, device discovered
|
||||||
async_discover.return_value = discoveries
|
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
|
# ensure device is stored/used
|
||||||
async_create_device.assert_called_with(hass, discoveries[1][DISCOVERY_LOCATION])
|
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()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user