Skip to content

Commit

Permalink
FIx Sonos announce regression issue (#125515)
Browse files Browse the repository at this point in the history
* initial commit

* initial commit
  • Loading branch information
PeteRager authored Sep 8, 2024
1 parent 8d0dda6 commit 2c48f9a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
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

0 comments on commit 2c48f9a

Please sign in to comment.