Ensure songpal config flow title_placeholders items are [str, str] (#127290)

This commit is contained in:
Erik Montnemery 2024-10-02 14:20:16 +02:00 committed by GitHub
parent 4726dc96d4
commit 083be5d0a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -106,7 +106,7 @@ class SongpalConfigFlow(ConfigFlow, domain=DOMAIN):
_LOGGER.debug("Discovered: %s", discovery_info) _LOGGER.debug("Discovered: %s", discovery_info)
friendly_name = discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME] friendly_name = discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]
parsed_url = urlparse(discovery_info.ssdp_location) hostname = urlparse(discovery_info.ssdp_location).hostname
scalarweb_info = discovery_info.upnp["X_ScalarWebAPI_DeviceInfo"] scalarweb_info = discovery_info.upnp["X_ScalarWebAPI_DeviceInfo"]
endpoint = scalarweb_info["X_ScalarWebAPI_BaseURL"] endpoint = scalarweb_info["X_ScalarWebAPI_BaseURL"]
service_types = scalarweb_info["X_ScalarWebAPI_ServiceList"][ service_types = scalarweb_info["X_ScalarWebAPI_ServiceList"][
@ -117,14 +117,17 @@ class SongpalConfigFlow(ConfigFlow, domain=DOMAIN):
if "videoScreen" in service_types: if "videoScreen" in service_types:
return self.async_abort(reason="not_songpal_device") return self.async_abort(reason="not_songpal_device")
if TYPE_CHECKING:
# the hostname must be str because the ssdp_location is not bytes and
# not a relative url
assert isinstance(hostname, str)
self.context["title_placeholders"] = { self.context["title_placeholders"] = {
CONF_NAME: friendly_name, CONF_NAME: friendly_name,
CONF_HOST: parsed_url.hostname, CONF_HOST: hostname,
} }
if TYPE_CHECKING: self.conf = SongpalConfig(friendly_name, hostname, endpoint)
assert isinstance(parsed_url.hostname, str)
self.conf = SongpalConfig(friendly_name, parsed_url.hostname, endpoint)
return await self.async_step_init() return await self.async_step_init()