Exceptions during Sonos Unjoin action results in hung script (#159779)

This commit is contained in:
Pete Sage
2025-12-26 20:20:12 +01:00
committed by GitHub
parent 45ba7e0df1
commit e639ebc269
5 changed files with 60 additions and 10 deletions
+33 -1
View File
@@ -13,6 +13,7 @@ from homeassistant.components.media_player import (
SERVICE_JOIN,
SERVICE_UNJOIN,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er
@@ -131,7 +132,7 @@ async def test_media_player_join_timeout(
expected = (
"Timeout while waiting for Sonos player to join the "
"group ['Living Room: Living Room, Bedroom']"
"group Living Room: Living Room, Bedroom"
)
with (
patch(
@@ -153,6 +154,37 @@ async def test_media_player_join_timeout(
assert soco_living_room.join.call_count == 0
async def test_media_player_unjoin_timeout(
hass: HomeAssistant,
sonos_setup_two_speakers: list[MockSoCo],
) -> None:
"""Test unjoining of speaker with timeout error."""
soco_living_room = sonos_setup_two_speakers[0]
soco_bedroom = sonos_setup_two_speakers[1]
# First group the speakers together
group_speakers(soco_living_room, soco_bedroom)
await hass.async_block_till_done(wait_background_tasks=True)
expected = (
"Timeout while waiting for Sonos player to unjoin the group Bedroom: Bedroom"
)
with (
patch(
"homeassistant.components.sonos.speaker.asyncio.timeout", instant_timeout
),
pytest.raises(HomeAssistantError, match=re.escape(expected)),
):
await hass.services.async_call(
MP_DOMAIN,
SERVICE_UNJOIN,
{ATTR_ENTITY_ID: "media_player.bedroom"},
blocking=True,
)
assert soco_bedroom.unjoin.call_count == 1
async def test_media_player_unjoin(
hass: HomeAssistant,
sonos_setup_two_speakers: list[MockSoCo],