From b462038126f84e461e60c3570d2f7000153b9d92 Mon Sep 17 00:00:00 2001 From: Pete Sage <76050312+PeteRager@users.noreply.github.com> Date: Fri, 2 Jan 2026 08:18:56 -0500 Subject: [PATCH] Use long service timeout for Sonos Unjoin (#160110) --- homeassistant/components/sonos/const.py | 1 + homeassistant/components/sonos/media_player.py | 2 +- homeassistant/components/sonos/speaker.py | 3 ++- tests/components/sonos/test_services.py | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/sonos/const.py b/homeassistant/components/sonos/const.py index 49b823d4c6b..82416bd1965 100644 --- a/homeassistant/components/sonos/const.py +++ b/homeassistant/components/sonos/const.py @@ -212,3 +212,4 @@ BATTERY_SCAN_INTERVAL = datetime.timedelta(minutes=15) SCAN_INTERVAL = datetime.timedelta(seconds=10) DISCOVERY_INTERVAL = datetime.timedelta(seconds=60) SUBSCRIPTION_TIMEOUT = 1200 +LONG_SERVICE_TIMEOUT = 30.0 diff --git a/homeassistant/components/sonos/media_player.py b/homeassistant/components/sonos/media_player.py index cb48037524e..f7a4420704b 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -54,6 +54,7 @@ from . import media_browser from .const import ( ATTR_QUEUE_POSITION, DOMAIN, + LONG_SERVICE_TIMEOUT, MEDIA_TYPE_DIRECTORY, MEDIA_TYPES_TO_SONOS, MODELS_LINEIN_AND_TV, @@ -76,7 +77,6 @@ if TYPE_CHECKING: _LOGGER = logging.getLogger(__name__) -LONG_SERVICE_TIMEOUT = 30.0 UNJOIN_SERVICE_TIMEOUT = 0.1 VOLUME_INCREMENT = 2 diff --git a/homeassistant/components/sonos/speaker.py b/homeassistant/components/sonos/speaker.py index dd1ecca4227..317ffbc13d9 100644 --- a/homeassistant/components/sonos/speaker.py +++ b/homeassistant/components/sonos/speaker.py @@ -40,6 +40,7 @@ from .const import ( AVAILABILITY_TIMEOUT, BATTERY_SCAN_INTERVAL, DOMAIN, + LONG_SERVICE_TIMEOUT, SCAN_INTERVAL, SONOS_CHECK_ACTIVITY, SONOS_CREATE_ALARM, @@ -1067,7 +1068,7 @@ class SonosSpeaker: """Unjoin the player from a group.""" if self.sonos_group == [self]: return - self.soco.unjoin() + self.soco.unjoin(timeout=LONG_SERVICE_TIMEOUT) @staticmethod async def unjoin_multi( diff --git a/tests/components/sonos/test_services.py b/tests/components/sonos/test_services.py index 7e30e1e2125..af8177a901c 100644 --- a/tests/components/sonos/test_services.py +++ b/tests/components/sonos/test_services.py @@ -13,6 +13,7 @@ from homeassistant.components.media_player import ( SERVICE_JOIN, SERVICE_UNJOIN, ) +from homeassistant.components.sonos.const import LONG_SERVICE_TIMEOUT from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -222,7 +223,7 @@ async def test_media_player_unjoin( await hass.async_block_till_done(wait_background_tasks=True) assert len(caplog.records) == 0 - assert soco_bedroom.unjoin.call_count == 1 + soco_bedroom.unjoin.assert_called_with(timeout=LONG_SERVICE_TIMEOUT) assert soco_living_room.unjoin.call_count == 0