Add warning if Sonos not linked to Plex (#58150)

This commit is contained in:
jjlawren 2021-10-24 17:51:45 -05:00 committed by GitHub
parent 2a6247cf20
commit 3672889609
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -2,7 +2,7 @@
import json
import logging
from plexapi.exceptions import NotFound
from plexapi.exceptions import BadRequest, NotFound
import voluptuous as vol
from homeassistant.exceptions import HomeAssistantError
@ -133,7 +133,13 @@ def play_on_sonos(hass, content_type, content_id, speaker_name):
Called by Sonos 'media_player.play_media' service.
"""
media, plex_server = lookup_plex_media(hass, content_type, content_id)
sonos_speaker = plex_server.account.sonos_speaker(speaker_name)
try:
sonos_speaker = plex_server.account.sonos_speaker(speaker_name)
except BadRequest as exc:
raise HomeAssistantError(
"Sonos speakers not linked to Plex account, complete this step in the Plex app"
) from exc
if sonos_speaker is None:
message = f"Sonos speaker '{speaker_name}' is not associated with '{plex_server.friendly_name}'"
_LOGGER.error(message)