mirror of
https://github.com/home-assistant/core
synced 2024-08-02 23:40:32 +02:00
Tidy up ssdp_location parsing (#60846)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
36734972f0
commit
d775c66194
@ -1,4 +1,5 @@
|
||||
"""Config flow to configure Heos."""
|
||||
from typing import TYPE_CHECKING
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from pyheos import Heos, HeosError
|
||||
@ -25,7 +26,9 @@ class HeosFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||
"""Handle a discovered Heos device."""
|
||||
# Store discovered host
|
||||
hostname = urlparse(discovery_info.ssdp_location or "").hostname
|
||||
if TYPE_CHECKING:
|
||||
assert discovery_info.ssdp_location
|
||||
hostname = urlparse(discovery_info.ssdp_location).hostname
|
||||
friendly_name = (
|
||||
f"{discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]} ({hostname})"
|
||||
)
|
||||
|
@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from huawei_lte_api.AuthorizedConnection import AuthorizedConnection
|
||||
@ -214,10 +214,12 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
):
|
||||
return self.async_abort(reason="not_huawei_lte")
|
||||
|
||||
if TYPE_CHECKING:
|
||||
assert discovery_info.ssdp_location
|
||||
url = url_normalize(
|
||||
discovery_info.upnp.get(
|
||||
ssdp.ATTR_UPNP_PRESENTATION_URL,
|
||||
f"http://{urlparse(discovery_info.ssdp_location or '').hostname}/",
|
||||
f"http://{urlparse(discovery_info.ssdp_location).hostname}/",
|
||||
)
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user