mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
commit
b0b88e606c
@ -15,8 +15,6 @@ media_player:
|
|||||||
import logging
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
REQUIREMENTS = ['SoCo==0.11.1']
|
|
||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
MediaPlayerDevice, SUPPORT_PAUSE, SUPPORT_SEEK, SUPPORT_VOLUME_SET,
|
MediaPlayerDevice, SUPPORT_PAUSE, SUPPORT_SEEK, SUPPORT_VOLUME_SET,
|
||||||
SUPPORT_VOLUME_MUTE, SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK,
|
SUPPORT_VOLUME_MUTE, SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK,
|
||||||
@ -26,6 +24,9 @@ from homeassistant.helpers.event import track_utc_time_change
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_IDLE, STATE_PLAYING, STATE_PAUSED, STATE_UNKNOWN)
|
STATE_IDLE, STATE_PLAYING, STATE_PAUSED, STATE_UNKNOWN)
|
||||||
|
|
||||||
|
|
||||||
|
REQUIREMENTS = ['SoCo==0.11.1']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SUPPORT_SONOS = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\
|
SUPPORT_SONOS = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\
|
||||||
@ -35,9 +36,15 @@ SUPPORT_SONOS = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\
|
|||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
""" Sets up the Sonos platform. """
|
""" Sets up the Sonos platform. """
|
||||||
|
|
||||||
import soco
|
import soco
|
||||||
add_devices(SonosDevice(hass, p) for p in soco.discover())
|
|
||||||
|
players = soco.discover()
|
||||||
|
if not players:
|
||||||
|
_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
|
return True
|
||||||
|
|
||||||
@ -113,6 +120,13 @@ class SonosDevice(MediaPlayerDevice):
|
|||||||
def media_duration(self):
|
def media_duration(self):
|
||||||
""" Duration of current playing media in seconds. """
|
""" Duration of current playing media in seconds. """
|
||||||
dur = self._trackinfo.get('duration', '0:00')
|
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
|
return sum(60 ** x[0] * int(x[1]) for x in
|
||||||
enumerate(reversed(dur.split(':'))))
|
enumerate(reversed(dur.split(':'))))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user