Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIx Sonos announce regression issue #125515

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions homeassistant/components/sonos/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
SONOS_TO_REPEAT = {meaning: mode for mode, meaning in REPEAT_TO_SONOS.items()}

UPNP_ERRORS_TO_IGNORE = ["701", "711", "712"]
ANNOUNCE_NOT_SUPPORTED_ERRORS: list[str] = ["globalError"]

SERVICE_SNAPSHOT = "snapshot"
SERVICE_RESTORE = "restore"
Expand Down Expand Up @@ -556,11 +557,24 @@ async def async_play_media(
) from exc
if response.get("success"):
return
raise HomeAssistantError(
translation_domain=SONOS_DOMAIN,
translation_key="announce_media_error",
translation_placeholders={"media_id": media_id, "response": response},
)
if response.get("type") in ANNOUNCE_NOT_SUPPORTED_ERRORS:
# If the speaker does not support announce do not raise and
# fall through to_play_media to play the clip directly.
_LOGGER.debug(
"Speaker %s does not support announce, media_id %s response %s",
self.speaker.zone_name,
media_id,
response,
)
else:
raise HomeAssistantError(
translation_domain=SONOS_DOMAIN,
translation_key="announce_media_error",
translation_placeholders={
"media_id": media_id,
"response": response,
},
)

if spotify.is_spotify_media_type(media_type):
media_type = spotify.resolve_spotify_media_type(media_type)
Expand Down
21 changes: 21 additions & 0 deletions tests/components/sonos/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,27 @@ async def test_play_media_announce(
)
assert sonos_websocket.play_clip.call_count == 1

# Test speakers that do not support announce. This
# will result in playing the clip directly via play_uri
sonos_websocket.play_clip.reset_mock()
sonos_websocket.play_clip.side_effect = None
retval = {"success": 0, "type": "globalError"}
sonos_websocket.play_clip.return_value = [retval, {}]

await hass.services.async_call(
MP_DOMAIN,
SERVICE_PLAY_MEDIA,
{
ATTR_ENTITY_ID: "media_player.zone_a",
ATTR_MEDIA_CONTENT_TYPE: "music",
ATTR_MEDIA_CONTENT_ID: content_id,
ATTR_MEDIA_ANNOUNCE: True,
},
blocking=True,
)
assert sonos_websocket.play_clip.call_count == 1
soco.play_uri.assert_called_with(content_id, force_radio=False)


async def test_media_get_queue(
hass: HomeAssistant,
Expand Down