Skip to content

Commit

Permalink
support more media_ids, limit updates
Browse files Browse the repository at this point in the history
  • Loading branch information
happyleavesaoc committed Apr 13, 2017
1 parent e57bf8a commit 0a8c5a5
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions homeassistant/components/media_player/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
"""

import logging
from datetime import timedelta

import voluptuous as vol

from homeassistant.core import callback
from homeassistant.loader import get_component
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.media_player import (
MEDIA_TYPE_MUSIC, SUPPORT_VOLUME_SET, SUPPORT_PLAY, SUPPORT_PAUSE,
SUPPORT_PLAY_MEDIA, SUPPORT_NEXT_TRACK, SUPPORT_PREVIOUS_TRACK,
SUPPORT_SELECT_SOURCE, PLATFORM_SCHEMA, MediaPlayerDevice)
MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST, SUPPORT_VOLUME_SET,
SUPPORT_PLAY, SUPPORT_PAUSE, SUPPORT_PLAY_MEDIA, SUPPORT_NEXT_TRACK,
SUPPORT_PREVIOUS_TRACK, SUPPORT_SELECT_SOURCE, PLATFORM_SCHEMA,
MediaPlayerDevice)
from homeassistant.const import (
CONF_NAME, STATE_PLAYING, STATE_PAUSED, STATE_UNKNOWN, STATE_IDLE)
CONF_NAME, STATE_PLAYING, STATE_PAUSED, STATE_IDLE, STATE_UNKNOWN)
import homeassistant.helpers.config_validation as cv


Expand Down Expand Up @@ -55,6 +57,8 @@
vol.Optional(CONF_CACHE_PATH): cv.string
})

SCAN_INTERVAL = timedelta(seconds=30)


def request_configuration(hass, config, add_devices, oauth):
"""Request Spotify authorization."""
Expand Down Expand Up @@ -211,10 +215,18 @@ def select_source(self, source):

def play_media(self, media_type, media_id, **kwargs):
"""Play media."""
kwargs = {}
if media_type == MEDIA_TYPE_MUSIC:
kwargs['uris'] = [media_id]
elif media_type == MEDIA_TYPE_PLAYLIST:
kwargs['context_uri'] = media_id
else:
_LOGGER.error('media type %s is not supported', media_type)
return
if not media_id.startswith('spotify:'):
_LOGGER.error('media id must be spotify uri')
return
self._player.start_playback(uris=[media_id])
self._player.start_playback(**kwargs)
self.schedule_update_ha_state()

@property
Expand Down Expand Up @@ -252,11 +264,6 @@ def media_content_id(self):
"""Media URL."""
return self._uri

@property
def media_content_type(self):
"""Media content type."""
return MEDIA_TYPE_MUSIC

@property
def media_image_url(self):
"""Media image url."""
Expand Down

0 comments on commit 0a8c5a5

Please sign in to comment.