1
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:
epenet 2021-12-02 18:47:20 +01:00 committed by GitHub
parent 36734972f0
commit d775c66194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -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})"
)

View File

@ -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}/",
)
)