Improve SSDP callback performance (#62359)

This commit is contained in:
J. Nick Koston 2021-12-19 23:04:45 -06:00 committed by GitHub
parent e8096e7f51
commit 70947b14a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -472,22 +472,24 @@ class Scanner:
)
location = ssdp_device.location
info_desc = await self._async_get_description_dict(location) or {}
info_desc = None
combined_headers = ssdp_device.combined_headers(dst)
info_with_desc = CaseInsensitiveDict(combined_headers, **info_desc)
callbacks = self._async_get_matching_callbacks(combined_headers)
matching_domains: set[str] = set()
# If there are no changes from a search, do not trigger a config flow
if source != SsdpSource.SEARCH_ALIVE:
info_desc = await self._async_get_description_dict(location) or {}
assert isinstance(combined_headers, CaseInsensitiveDict)
matching_domains = self.integration_matchers.async_matching_domains(
info_with_desc
CaseInsensitiveDict({**combined_headers.as_dict(), **info_desc})
)
if not callbacks and not matching_domains:
return
if info_desc is None:
info_desc = await self._async_get_description_dict(location) or {}
discovery_info = discovery_info_from_headers_and_description(
combined_headers, info_desc
)
@ -565,7 +567,10 @@ def discovery_info_from_headers_and_description(
"""Convert headers and description to discovery_info."""
ssdp_usn = combined_headers["usn"]
ssdp_st = combined_headers.get("st")
upnp_info = {**info_desc}
if isinstance(info_desc, CaseInsensitiveDict):
upnp_info = {**info_desc.as_dict()}
else:
upnp_info = {**info_desc}
# Increase compatibility: depending on the message type,
# either the ST (Search Target, from M-SEARCH messages)