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_CHECK_ACTIVITY,
SONOS_REBOOTED, SONOS_REBOOTED,
SONOS_SPEAKER_ACTIVITY, SONOS_SPEAKER_ACTIVITY,
SONOS_VANISHED,
UPNP_ST, UPNP_ST,
) )
from .favorites import SonosFavorites from .favorites import SonosFavorites
@ -274,14 +275,19 @@ class SonosDiscoveryManager:
async def _async_ssdp_discovered_player( async def _async_ssdp_discovered_player(
self, info: ssdp.SsdpServiceInfo, change: ssdp.SsdpChange self, info: ssdp.SsdpServiceInfo, change: ssdp.SsdpChange
) -> None: ) -> None:
if change == ssdp.SsdpChange.BYEBYE:
return
uid = info.upnp[ssdp.ATTR_UPNP_UDN] uid = info.upnp[ssdp.ATTR_UPNP_UDN]
if not uid.startswith("uuid:RINCON_"): if not uid.startswith("uuid:RINCON_"):
return return
uid = uid[5:] 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 discovered_ip = urlparse(info.ssdp_location).hostname
boot_seqnum = info.ssdp_headers.get("X-RINCON-BOOTSEQ") boot_seqnum = info.ssdp_headers.get("X-RINCON-BOOTSEQ")
self.async_discovered_player( self.async_discovered_player(