Sonos line-in and tv source fixes + Sonos discovery fix. (#4440)

* Fixes line-in and tv sources on Sonos + Sonos discovery fixes.

* Style fix.
This commit is contained in:
Bjarni Ivarsson 2016-11-19 16:29:00 +01:00 committed by Lewis Juggins
parent 8beefcfc69
commit f3748ce535

View File

@ -73,7 +73,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
player = soco.SoCo(discovery_info) player = soco.SoCo(discovery_info)
# if device allready exists by config # if device allready exists by config
if player.uid in DEVICES: if player.uid in [x.unique_id for x in DEVICES]:
return True return True
if player.is_visible: if player.is_visible:
@ -350,9 +350,6 @@ class SonosDevice(MediaPlayerDevice):
if is_available: if is_available:
self._is_playing_tv = self._player.is_playing_tv
self._is_playing_line_in = self._player.is_playing_line_in
track_info = None track_info = None
if self._last_avtransport_event: if self._last_avtransport_event:
variables = self._last_avtransport_event.variables variables = self._last_avtransport_event.variables
@ -394,6 +391,10 @@ class SonosDevice(MediaPlayerDevice):
self._coordinator = None self._coordinator = None
if not self._coordinator: if not self._coordinator:
is_playing_tv = self._player.is_playing_tv
is_playing_line_in = self._player.is_playing_line_in
media_info = self._player.avTransport.GetMediaInfo( media_info = self._player.avTransport.GetMediaInfo(
[('InstanceID', 0)] [('InstanceID', 0)]
) )
@ -407,7 +408,23 @@ class SonosDevice(MediaPlayerDevice):
current_media_uri.startswith('x-sonosapi-stream:') or \ current_media_uri.startswith('x-sonosapi-stream:') or \
current_media_uri.startswith('x-rincon-mp3radio:') current_media_uri.startswith('x-rincon-mp3radio:')
if is_radio_stream: if is_playing_tv or is_playing_line_in:
# playing from line-in/tv.
support_previous_track = False
support_next_track = False
support_pause = False
if is_playing_tv:
media_artist = SUPPORT_SOURCE_TV
else:
media_artist = SUPPORT_SOURCE_LINEIN
media_album_name = None
media_title = None
media_image_url = None
elif is_radio_stream:
is_radio_stream = True is_radio_stream = True
media_image_url = self._format_media_image_url( media_image_url = self._format_media_image_url(
current_media_uri current_media_uri
@ -506,6 +523,8 @@ class SonosDevice(MediaPlayerDevice):
self._support_previous_track = support_previous_track self._support_previous_track = support_previous_track
self._support_next_track = support_next_track self._support_next_track = support_next_track
self._support_pause = support_pause self._support_pause = support_pause
self._is_playing_tv = is_playing_tv
self._is_playing_line_in = is_playing_line_in
# update state of the whole group # update state of the whole group
# pylint: disable=protected-access # pylint: disable=protected-access
@ -513,7 +532,7 @@ class SonosDevice(MediaPlayerDevice):
if device.entity_id is not self.entity_id: if device.entity_id is not self.entity_id:
self.hass.add_job(device.async_update_ha_state) self.hass.add_job(device.async_update_ha_state)
if self._queue is None: if self._queue is None and self.entity_id is not None:
self._subscribe_to_player_events() self._subscribe_to_player_events()
else: else:
self._player_volume = None self._player_volume = None
@ -714,9 +733,12 @@ class SonosDevice(MediaPlayerDevice):
@property @property
def source(self): def source(self):
"""Name of the current input source.""" """Name of the current input source."""
if self._coordinator:
return self._coordinator.source
else:
if self._is_playing_line_in: if self._is_playing_line_in:
return SUPPORT_SOURCE_LINEIN return SUPPORT_SOURCE_LINEIN
if self._is_playing_tv: elif self._is_playing_tv:
return SUPPORT_SOURCE_TV return SUPPORT_SOURCE_TV
return None return None