Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure sonos always gets ssdp callbacks from searches #56591

Merged
merged 8 commits into from Sep 26, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions homeassistant/components/ssdp/__init__.py
Expand Up @@ -70,13 +70,13 @@


SSDP_SOURCE_SSDP_CHANGE_MAPPING: Mapping[SsdpSource, SsdpChange] = {
SsdpSource.SEARCH: SsdpChange.ALIVE,
SsdpSource.SEARCH_ALIVE: SsdpChange.ALIVE,
SsdpSource.SEARCH_CHANGED: SsdpChange.ALIVE,
SsdpSource.ADVERTISEMENT_ALIVE: SsdpChange.ALIVE,
SsdpSource.ADVERTISEMENT_BYEBYE: SsdpChange.BYEBYE,
SsdpSource.ADVERTISEMENT_UPDATE: SsdpChange.UPDATE,
}


_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -334,26 +334,37 @@ def _async_matching_domains(self, info_with_desc: CaseInsensitiveDict) -> set[st
return domains

async def _ssdp_listener_callback(
self, ssdp_device: SsdpDevice, dst: DeviceOrServiceType, source: SsdpSource
self,
ssdp_device: SsdpDevice,
dst: DeviceOrServiceType,
source: SsdpSource,
) -> None:
"""Handle a device/service change."""
_LOGGER.debug(
"Change, ssdp_device: %s, dst: %s, source: %s", ssdp_device, dst, source
"SSDP: ssdp_device: %s, dst: %s, source: %s", ssdp_device, dst, source
)

location = ssdp_device.location
info_desc = await self._async_get_description_dict(location) or {}
combined_headers = ssdp_device.combined_headers(dst)
info_with_desc = CaseInsensitiveDict(combined_headers, **info_desc)
discovery_info = discovery_info_from_headers_and_description(info_with_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:
StevenLooman marked this conversation as resolved.
Show resolved Hide resolved
matching_domains = self._async_matching_domains(info_with_desc)

if not callbacks and not matching_domains:
return

discovery_info = discovery_info_from_headers_and_description(info_with_desc)
ssdp_change = SSDP_SOURCE_SSDP_CHANGE_MAPPING[source]
await _async_process_callbacks(callbacks, discovery_info, ssdp_change)

for domain in self._async_matching_domains(info_with_desc):
for domain in matching_domains:
_LOGGER.debug("Discovered %s at %s", domain, location)

flow: SSDPFlow = {
"domain": domain,
"context": {"source": config_entries.SOURCE_SSDP},
Expand Down