Fix SSDP failure to start on missing URLs (#81453)

This commit is contained in:
Franck Nijhof 2022-11-03 11:13:23 +01:00 committed by GitHub
parent 203c83b6f0
commit 08772004b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,7 +52,7 @@ from homeassistant.helpers import discovery_flow
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.instance_id import async_get as async_get_instance_id from homeassistant.helpers.instance_id import async_get as async_get_instance_id
from homeassistant.helpers.network import get_url from homeassistant.helpers.network import NoURLAvailableError, get_url
from homeassistant.helpers.system_info import async_get_system_info from homeassistant.helpers.system_info import async_get_system_info
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import async_get_ssdp, bind_hass from homeassistant.loader import async_get_ssdp, bind_hass
@ -697,7 +697,16 @@ class Server:
udn = await self._async_get_instance_udn() udn = await self._async_get_instance_udn()
system_info = await async_get_system_info(self.hass) system_info = await async_get_system_info(self.hass)
model_name = system_info["installation_type"] model_name = system_info["installation_type"]
presentation_url = get_url(self.hass, allow_ip=True, prefer_external=False) try:
presentation_url = get_url(self.hass, allow_ip=True, prefer_external=False)
except NoURLAvailableError:
_LOGGER.warning(
"Could not set up UPnP/SSDP server, as a presentation URL could"
" not be determined; Please configure your internal URL"
" in the Home Assistant general configuration"
)
return
serial_number = await async_get_instance_id(self.hass) serial_number = await async_get_instance_id(self.hass)
HassUpnpServiceDevice.DEVICE_DEFINITION = ( HassUpnpServiceDevice.DEVICE_DEFINITION = (
HassUpnpServiceDevice.DEVICE_DEFINITION._replace( HassUpnpServiceDevice.DEVICE_DEFINITION._replace(