mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Fix a bug which causes the sonos component to occasionally pop
Had this happen when Sonos surround sound is playing from a TV. See this
for more details:
af9a5152fe/soco/core.py (L1060)
This commit is contained in:
parent
4fa379419d
commit
57a833f1a7
@ -36,15 +36,15 @@ SUPPORT_SONOS = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the Sonos platform. """
|
||||
|
||||
import soco
|
||||
|
||||
players = soco.discover()
|
||||
if not players:
|
||||
_LOGGER.warning('No Sonos speakers found. Disabling: ' + __name__)
|
||||
_LOGGER.warning('No Sonos speakers found. Disabling: %s', __name__)
|
||||
return False
|
||||
|
||||
add_devices(SonosDevice(hass, p) for p in players)
|
||||
_LOGGER.info('Added %s Sonos speakers', len(players))
|
||||
|
||||
return True
|
||||
|
||||
@ -120,6 +120,13 @@ class SonosDevice(MediaPlayerDevice):
|
||||
def media_duration(self):
|
||||
""" Duration of current playing media in seconds. """
|
||||
dur = self._trackinfo.get('duration', '0:00')
|
||||
|
||||
# If the speaker is playing from the "line-in" source, getting
|
||||
# track metadata can return NOT_IMPLEMENTED, which breaks the
|
||||
# volume logic below
|
||||
if dur == 'NOT_IMPLEMENTED':
|
||||
return None
|
||||
|
||||
return sum(60 ** x[0] * int(x[1]) for x in
|
||||
enumerate(reversed(dur.split(':'))))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user