2018-09-17 20:08:09 +00:00
|
|
|
"""Test UPnP/IGD setup process."""
|
2021-08-13 16:13:25 +00:00
|
|
|
from __future__ import annotations
|
2018-08-29 19:19:04 +00:00
|
|
|
|
2021-08-13 16:13:25 +00:00
|
|
|
import pytest
|
2021-01-01 21:31:56 +00:00
|
|
|
|
2022-01-07 13:10:11 +00:00
|
|
|
from homeassistant.components import ssdp
|
|
|
|
from homeassistant.components.upnp import UpnpDataUpdateCoordinator
|
2020-05-03 01:03:54 +00:00
|
|
|
from homeassistant.components.upnp.const import (
|
2021-01-29 09:23:34 +00:00
|
|
|
CONFIG_ENTRY_ST,
|
|
|
|
CONFIG_ENTRY_UDN,
|
|
|
|
DOMAIN,
|
2020-05-03 01:03:54 +00:00
|
|
|
)
|
2022-01-07 13:10:11 +00:00
|
|
|
from homeassistant.components.upnp.device import Device
|
2021-09-11 23:38:16 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2018-08-29 19:19:04 +00:00
|
|
|
|
2022-01-07 13:10:11 +00:00
|
|
|
from .conftest import TEST_DISCOVERY, TEST_ST, TEST_UDN
|
2018-08-29 19:19:04 +00:00
|
|
|
|
2020-05-03 01:03:54 +00:00
|
|
|
from tests.common import MockConfigEntry
|
2018-09-07 22:11:23 +00:00
|
|
|
|
|
|
|
|
2021-09-11 23:38:16 +00:00
|
|
|
@pytest.mark.usefixtures("ssdp_instant_discovery", "mock_get_source_ip")
|
2021-04-22 14:53:57 +00:00
|
|
|
async def test_async_setup_entry_default(hass: HomeAssistant):
|
2018-08-29 19:19:04 +00:00
|
|
|
"""Test async_setup_entry."""
|
2020-05-03 01:03:54 +00:00
|
|
|
entry = MockConfigEntry(
|
2021-01-29 11:27:57 +00:00
|
|
|
domain=DOMAIN,
|
2021-01-29 09:23:34 +00:00
|
|
|
data={
|
2021-08-13 16:13:25 +00:00
|
|
|
CONFIG_ENTRY_UDN: TEST_UDN,
|
|
|
|
CONFIG_ENTRY_ST: TEST_ST,
|
2021-01-29 09:23:34 +00:00
|
|
|
},
|
2020-05-03 01:03:54 +00:00
|
|
|
)
|
2018-08-30 14:38:43 +00:00
|
|
|
|
2021-08-13 16:13:25 +00:00
|
|
|
# Load config_entry.
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
assert await hass.config_entries.async_setup(entry.entry_id) is True
|
2022-01-07 13:10:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_reinitialize_device(
|
|
|
|
hass: HomeAssistant, setup_integration: MockConfigEntry
|
|
|
|
):
|
|
|
|
"""Test device is reinitialized when device changes location."""
|
|
|
|
config_entry = setup_integration
|
|
|
|
coordinator: UpnpDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
device: Device = coordinator.device
|
|
|
|
assert device._igd_device.device.device_url == TEST_DISCOVERY.ssdp_location
|
|
|
|
|
|
|
|
# Reinit.
|
|
|
|
new_location = "http://192.168.1.1:12345/desc.xml"
|
2022-02-05 05:33:53 +00:00
|
|
|
await device.async_ssdp_callback(
|
|
|
|
ssdp.SsdpServiceInfo(
|
|
|
|
ssdp_usn="mock_usn",
|
|
|
|
ssdp_st="mock_st",
|
|
|
|
ssdp_location="http://192.168.1.1:12345/desc.xml",
|
|
|
|
upnp={},
|
|
|
|
),
|
|
|
|
...,
|
|
|
|
)
|
2022-01-07 13:10:11 +00:00
|
|
|
assert device._igd_device.device.device_url == new_location
|