diff --git a/homeassistant/components/sonos/__init__.py b/homeassistant/components/sonos/__init__.py index 673e0ac4dfe..5f3cc285517 100644 --- a/homeassistant/components/sonos/__init__.py +++ b/homeassistant/components/sonos/__init__.py @@ -38,6 +38,7 @@ from .const import ( SONOS_CHECK_ACTIVITY, SONOS_REBOOTED, SONOS_SPEAKER_ACTIVITY, + SONOS_VANISHED, UPNP_ST, ) from .favorites import SonosFavorites @@ -274,14 +275,19 @@ class SonosDiscoveryManager: async def _async_ssdp_discovered_player( self, info: ssdp.SsdpServiceInfo, change: ssdp.SsdpChange ) -> None: - if change == ssdp.SsdpChange.BYEBYE: - return - uid = info.upnp[ssdp.ATTR_UPNP_UDN] if not uid.startswith("uuid:RINCON_"): return - uid = uid[5:] + + if change == ssdp.SsdpChange.BYEBYE: + _LOGGER.debug( + "ssdp:byebye received from %s", info.upnp.get("friendlyName", uid) + ) + reason = info.ssdp_headers.get("X-RINCON-REASON", "ssdp:byebye") + async_dispatcher_send(self.hass, f"{SONOS_VANISHED}-{uid}", reason) + return + discovered_ip = urlparse(info.ssdp_location).hostname boot_seqnum = info.ssdp_headers.get("X-RINCON-BOOTSEQ") self.async_discovered_player(