mirror of
https://github.com/home-assistant/core.git
synced 2025-05-03 13:39:16 +00:00
Clean up Sonos resubscription failure logic and logging (#50831)
This commit is contained in:
parent
3d5b354def
commit
ab86c7a135
@ -136,6 +136,7 @@ class SonosSpeaker:
|
|||||||
|
|
||||||
self._is_ready: bool = False
|
self._is_ready: bool = False
|
||||||
self._subscriptions: list[SubscriptionBase] = []
|
self._subscriptions: list[SubscriptionBase] = []
|
||||||
|
self._resubscription_lock: asyncio.Lock | None = None
|
||||||
self._poll_timer: Callable | None = None
|
self._poll_timer: Callable | None = None
|
||||||
self._seen_timer: Callable | None = None
|
self._seen_timer: Callable | None = None
|
||||||
self._platforms_ready: set[str] = set()
|
self._platforms_ready: set[str] = set()
|
||||||
@ -198,6 +199,7 @@ class SonosSpeaker:
|
|||||||
"""Listen to new entities to trigger first subscription."""
|
"""Listen to new entities to trigger first subscription."""
|
||||||
self._platforms_ready.add(entity_type)
|
self._platforms_ready.add(entity_type)
|
||||||
if self._platforms_ready == PLATFORMS:
|
if self._platforms_ready == PLATFORMS:
|
||||||
|
self._resubscription_lock = asyncio.Lock()
|
||||||
await self.async_subscribe()
|
await self.async_subscribe()
|
||||||
self._is_ready = True
|
self._is_ready = True
|
||||||
|
|
||||||
@ -313,11 +315,27 @@ class SonosSpeaker:
|
|||||||
|
|
||||||
self.async_write_entity_states()
|
self.async_write_entity_states()
|
||||||
|
|
||||||
|
async def async_resubscribe(self, exception: Exception) -> None:
|
||||||
|
"""Attempt to resubscribe when a renewal failure is detected."""
|
||||||
|
async with self._resubscription_lock:
|
||||||
|
if self.available:
|
||||||
|
if getattr(exception, "status", None) == 412:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Subscriptions for %s failed, speaker may have lost power",
|
||||||
|
self.zone_name,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Subscription renewals for %s failed",
|
||||||
|
self.zone_name,
|
||||||
|
exc_info=exception,
|
||||||
|
)
|
||||||
|
await self.async_unseen()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_renew_failed(self, exception: Exception) -> None:
|
def async_renew_failed(self, exception: Exception) -> None:
|
||||||
"""Handle a failed subscription renewal."""
|
"""Handle a failed subscription renewal."""
|
||||||
if self.available:
|
self.hass.async_create_task(self.async_resubscribe(exception))
|
||||||
self.hass.async_add_job(self.async_unseen)
|
|
||||||
|
|
||||||
async def async_unseen(self, now: datetime.datetime | None = None) -> None:
|
async def async_unseen(self, now: 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."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user