1
mirror of https://github.com/home-assistant/core synced 2024-07-27 18:58:57 +02:00

Use SSDP byebye to mark Sonos as offline (#65686)

This commit is contained in:
jjlawren 2022-02-04 13:41:24 -06:00 committed by GitHub
parent bebf5009d6
commit 40857bda90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(