From d775c66194ff22b8cf2b63430957ccda21b4b7be Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 2 Dec 2021 18:47:20 +0100 Subject: [PATCH] Tidy up ssdp_location parsing (#60846) Co-authored-by: epenet --- homeassistant/components/heos/config_flow.py | 5 ++++- homeassistant/components/huawei_lte/config_flow.py | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/heos/config_flow.py b/homeassistant/components/heos/config_flow.py index 5e534e3e986..63a020c41d9 100644 --- a/homeassistant/components/heos/config_flow.py +++ b/homeassistant/components/heos/config_flow.py @@ -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})" ) diff --git a/homeassistant/components/huawei_lte/config_flow.py b/homeassistant/components/huawei_lte/config_flow.py index 9c9bbb7ee54..be2a149b4d5 100644 --- a/homeassistant/components/huawei_lte/config_flow.py +++ b/homeassistant/components/huawei_lte/config_flow.py @@ -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}/", ) )