Defer SSDP UPNP server start until the started event (#96555)
This commit is contained in:
parent
c95e2c074c
commit
1c814b0ee3
2 changed files with 10 additions and 4 deletions
|
@ -42,11 +42,12 @@ from async_upnp_client.utils import CaseInsensitiveDict
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.components import network
|
||||
from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_STARTED,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
MATCH_ALL,
|
||||
__version__ as current_version,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback as core_callback
|
||||
from homeassistant.core import Event, HomeAssistant, callback as core_callback
|
||||
from homeassistant.data_entry_flow import BaseServiceInfo
|
||||
from homeassistant.helpers import config_validation as cv, discovery_flow
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
@ -728,15 +729,18 @@ class Server:
|
|||
|
||||
async def async_start(self) -> None:
|
||||
"""Start the server."""
|
||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.async_stop)
|
||||
await self._async_start_upnp_servers()
|
||||
bus = self.hass.bus
|
||||
bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.async_stop)
|
||||
bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STARTED, self._async_start_upnp_servers
|
||||
)
|
||||
|
||||
async def _async_get_instance_udn(self) -> str:
|
||||
"""Get Unique Device Name for this instance."""
|
||||
instance_id = await async_get_instance_id(self.hass)
|
||||
return f"uuid:{instance_id[0:8]}-{instance_id[8:12]}-{instance_id[12:16]}-{instance_id[16:20]}-{instance_id[20:32]}".upper()
|
||||
|
||||
async def _async_start_upnp_servers(self) -> None:
|
||||
async def _async_start_upnp_servers(self, event: Event) -> None:
|
||||
"""Start the UPnP/SSDP servers."""
|
||||
# Update UDN with our instance UDN.
|
||||
udn = await self._async_get_instance_udn()
|
||||
|
|
|
@ -742,6 +742,8 @@ async def test_bind_failure_skips_adapter(
|
|||
SsdpListener.async_start = _async_start
|
||||
UpnpServer.async_start = _async_start
|
||||
await init_ssdp_component(hass)
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "Failed to setup listener for" in caplog.text
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue