mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Defer SSDP UPNP server start until the started event (#96555)
This commit is contained in:
parent
c95e2c074c
commit
1c814b0ee3
@ -42,11 +42,12 @@ from async_upnp_client.utils import CaseInsensitiveDict
|
|||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import network
|
from homeassistant.components import network
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
MATCH_ALL,
|
MATCH_ALL,
|
||||||
__version__ as current_version,
|
__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.data_entry_flow import BaseServiceInfo
|
||||||
from homeassistant.helpers import config_validation as cv, discovery_flow
|
from homeassistant.helpers import config_validation as cv, discovery_flow
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
@ -728,15 +729,18 @@ class Server:
|
|||||||
|
|
||||||
async def async_start(self) -> None:
|
async def async_start(self) -> None:
|
||||||
"""Start the server."""
|
"""Start the server."""
|
||||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.async_stop)
|
bus = self.hass.bus
|
||||||
await self._async_start_upnp_servers()
|
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:
|
async def _async_get_instance_udn(self) -> str:
|
||||||
"""Get Unique Device Name for this instance."""
|
"""Get Unique Device Name for this instance."""
|
||||||
instance_id = await async_get_instance_id(self.hass)
|
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()
|
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."""
|
"""Start the UPnP/SSDP servers."""
|
||||||
# Update UDN with our instance UDN.
|
# Update UDN with our instance UDN.
|
||||||
udn = await self._async_get_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
|
SsdpListener.async_start = _async_start
|
||||||
UpnpServer.async_start = _async_start
|
UpnpServer.async_start = _async_start
|
||||||
await init_ssdp_component(hass)
|
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
|
assert "Failed to setup listener for" in caplog.text
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user