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