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,12 +399,19 @@ 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):
message = "Request timed out"
exc_info = None
elif isinstance(result, Exception):
message = result
exc_info = result if not str(result) else None
else:
continue
_LOGGER.debug( _LOGGER.debug(
"Unsubscribe failed for %s: %s", "Unsubscribe failed for %s: %s",
self.zone_name, self.zone_name,
result, message,
exc_info=result, exc_info=exc_info,
) )
self._subscriptions = [] self._subscriptions = []
@ -422,17 +429,16 @@ 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(
"Subscription renewals for %s failed, marking unavailable: %s",
self.zone_name, self.zone_name,
exception, message,
exc_info=exc_info, exc_info=exc_info,
) )
await self.async_offline() await self.async_offline()