mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Handle Sonos subscription renewal failures (#50793)
This commit is contained in:
parent
9e681cd214
commit
8129db1cfe
@ -147,3 +147,4 @@ BATTERY_SCAN_INTERVAL = datetime.timedelta(minutes=15)
|
|||||||
SCAN_INTERVAL = datetime.timedelta(seconds=10)
|
SCAN_INTERVAL = datetime.timedelta(seconds=10)
|
||||||
DISCOVERY_INTERVAL = datetime.timedelta(seconds=60)
|
DISCOVERY_INTERVAL = datetime.timedelta(seconds=60)
|
||||||
SEEN_EXPIRE_TIME = 3.5 * DISCOVERY_INTERVAL
|
SEEN_EXPIRE_TIME = 3.5 * DISCOVERY_INTERVAL
|
||||||
|
SUBSCRIPTION_TIMEOUT = 1200
|
||||||
|
@ -48,6 +48,7 @@ from .const import (
|
|||||||
SONOS_STATE_UPDATED,
|
SONOS_STATE_UPDATED,
|
||||||
SOURCE_LINEIN,
|
SOURCE_LINEIN,
|
||||||
SOURCE_TV,
|
SOURCE_TV,
|
||||||
|
SUBSCRIPTION_TIMEOUT,
|
||||||
)
|
)
|
||||||
from .favorites import SonosFavorites
|
from .favorites import SonosFavorites
|
||||||
from .helpers import soco_error
|
from .helpers import soco_error
|
||||||
@ -251,8 +252,11 @@ class SonosSpeaker:
|
|||||||
self, target: SubscriptionBase, sub_callback: Callable
|
self, target: SubscriptionBase, sub_callback: Callable
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create a Sonos subscription."""
|
"""Create a Sonos subscription."""
|
||||||
subscription = await target.subscribe(auto_renew=True)
|
subscription = await target.subscribe(
|
||||||
|
auto_renew=True, requested_timeout=SUBSCRIPTION_TIMEOUT
|
||||||
|
)
|
||||||
subscription.callback = sub_callback
|
subscription.callback = sub_callback
|
||||||
|
subscription.auto_renew_fail = self.async_renew_failed
|
||||||
self._subscriptions.append(subscription)
|
self._subscriptions.append(subscription)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -309,10 +313,18 @@ class SonosSpeaker:
|
|||||||
|
|
||||||
self.async_write_entity_states()
|
self.async_write_entity_states()
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_renew_failed(self, exception: Exception) -> None:
|
||||||
|
"""Handle a failed subscription renewal."""
|
||||||
|
if self.available:
|
||||||
|
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."""
|
||||||
self.async_write_entity_states()
|
self.async_write_entity_states()
|
||||||
|
|
||||||
|
if self._seen_timer:
|
||||||
|
self._seen_timer()
|
||||||
self._seen_timer = None
|
self._seen_timer = None
|
||||||
|
|
||||||
if self._poll_timer:
|
if self._poll_timer:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user