Skip Sonos zeroconf availability check in non-timeout scenarios (#54425)

This commit is contained in:
jjlawren 2021-08-13 15:42:55 -05:00 committed by GitHub
parent 8264fd2eb6
commit f4fb5f2f5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -499,21 +499,26 @@ class SonosSpeaker:
self.async_write_entity_states()
async def async_unseen(self, now: datetime.datetime | None = None) -> None:
async def async_unseen(
self, callback_timestamp: datetime.datetime | None = None
) -> None:
"""Make this player unavailable when it was not seen recently."""
if self._seen_timer:
self._seen_timer()
self._seen_timer = None
hostname = uid_to_short_hostname(self.soco.uid)
zcname = f"{hostname}.{MDNS_SERVICE}"
aiozeroconf = await zeroconf.async_get_async_instance(self.hass)
if await aiozeroconf.async_get_service_info(MDNS_SERVICE, zcname):
# We can still see the speaker via zeroconf check again later.
self._seen_timer = self.hass.helpers.event.async_call_later(
SEEN_EXPIRE_TIME.total_seconds(), self.async_unseen
)
return
if callback_timestamp:
# Called by a _seen_timer timeout, check mDNS one more time
# This should not be checked in an "active" unseen scenario
hostname = uid_to_short_hostname(self.soco.uid)
zcname = f"{hostname}.{MDNS_SERVICE}"
aiozeroconf = await zeroconf.async_get_async_instance(self.hass)
if await aiozeroconf.async_get_service_info(MDNS_SERVICE, zcname):
# We can still see the speaker via zeroconf check again later.
self._seen_timer = self.hass.helpers.event.async_call_later(
SEEN_EXPIRE_TIME.total_seconds(), self.async_unseen
)
return
_LOGGER.debug(
"No activity and could not locate %s on the network. Marking unavailable",