Fix Sonos speaker lookup for Plex (#37942)

This commit is contained in:
jjlawren authored and Paulus Schoutsen committed 2020-07-18 23:37:48 +00:00
1 parent 757d05a74e
commit a3429848a2
4 files changed
+19 -17

No files matched your search

+3 -3
View File
@@ -215,7 +215,7 @@ def play_on_sonos(hass, service_call):
sonos = hass.components.sonos
try:
sonos_id = sonos.get_coordinator_id(entity_id)
sonos_name = sonos.get_coordinator_name(entity_id)
except HomeAssistantError as err:
_LOGGER.error("Cannot get Sonos device: %s", err)
return
@@ -239,10 +239,10 @@ def play_on_sonos(hass, service_call):
else:
plex_server = next(iter(plex_servers))
sonos_speaker = plex_server.account.sonos_speaker_by_id(sonos_id)
sonos_speaker = plex_server.account.sonos_speaker(sonos_name)
if sonos_speaker is None:
_LOGGER.error(
"Sonos speaker '%s' could not be found on this Plex account", sonos_id
"Sonos speaker '%s' could not be found on this Plex account", sonos_name
)
return
+6 -4
View File
@@ -58,8 +58,10 @@ async def async_setup_entry(hass, entry):
@bind_hass
def get_coordinator_id(hass, entity_id):
"""Obtain the unique_id of a device's coordinator.
def get_coordinator_name(hass, entity_id):
"""Obtain the room/name of a device's coordinator.
Used by the Plex integration.
This function is safe to run inside the event loop.
"""
@@ -71,5 +73,5 @@ def get_coordinator_id(hass, entity_id):
)
if device.is_coordinator:
return device.unique_id
return device.coordinator.unique_id
return device.name
return device.coordinator.name