mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00: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."""
|
"""Config flow to configure Heos."""
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from pyheos import Heos, HeosError
|
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:
|
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||||
"""Handle a discovered Heos device."""
|
"""Handle a discovered Heos device."""
|
||||||
# Store discovered host
|
# 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 = (
|
friendly_name = (
|
||||||
f"{discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]} ({hostname})"
|
f"{discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]} ({hostname})"
|
||||||
)
|
)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from huawei_lte_api.AuthorizedConnection import AuthorizedConnection
|
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")
|
return self.async_abort(reason="not_huawei_lte")
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert discovery_info.ssdp_location
|
||||||
url = url_normalize(
|
url = url_normalize(
|
||||||
discovery_info.upnp.get(
|
discovery_info.upnp.get(
|
||||||
ssdp.ATTR_UPNP_PRESENTATION_URL,
|
ssdp.ATTR_UPNP_PRESENTATION_URL,
|
||||||
f"http://{urlparse(discovery_info.ssdp_location or '').hostname}/",
|
f"http://{urlparse(discovery_info.ssdp_location).hostname}/",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user