Clean up Sonos unsubscribe/resubscribe exception handling and logging (#66025)

This commit is contained in:
jjlawren 2022-02-07 18:00:57 -06:00 committed by Paulus Schoutsen
parent 02cb879717
commit 715fe95abd

View File

@ -399,13 +399,20 @@ class SonosSpeaker:
return_exceptions=True, return_exceptions=True,
) )
for result in results: for result in results:
if isinstance(result, Exception): if isinstance(result, asyncio.exceptions.TimeoutError):
_LOGGER.debug( message = "Request timed out"
"Unsubscribe failed for %s: %s", exc_info = None
self.zone_name, elif isinstance(result, Exception):
result, message = result
exc_info=result, exc_info = result if not str(result) else None
) else:
continue
_LOGGER.debug(
"Unsubscribe failed for %s: %s",
self.zone_name,
message,
exc_info=exc_info,
)
self._subscriptions = [] self._subscriptions = []
@callback @callback
@ -422,19 +429,18 @@ class SonosSpeaker:
if not self.available: if not self.available:
return return
if getattr(exception, "status", None) == 412: if isinstance(exception, asyncio.exceptions.TimeoutError):
_LOGGER.warning( message = "Request timed out"
"Subscriptions for %s failed, speaker may have lost power", exc_info = None
self.zone_name,
)
else: else:
exc_info = exception if _LOGGER.isEnabledFor(logging.DEBUG) else None message = exception
_LOGGER.error( exc_info = exception if not str(exception) else None
"Subscription renewals for %s failed: %s", _LOGGER.warning(
self.zone_name, "Subscription renewals for %s failed, marking unavailable: %s",
exception, self.zone_name,
exc_info=exc_info, message,
) exc_info=exc_info,
)
await self.async_offline() await self.async_offline()
@callback @callback