Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions homeassistant/components/media_player/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
ICON = 'mdi:spotify'
DEFAULT_NAME = 'Spotify'
DOMAIN = 'spotify'
CONF_ALIASES = 'aliases'
CONF_CLIENT_ID = 'client_id'
CONF_CLIENT_SECRET = 'client_secret'
CONF_CACHE_PATH = 'cache_path'
Expand All @@ -52,7 +53,8 @@
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CLIENT_SECRET): cv.string,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_CACHE_PATH): cv.string
vol.Optional(CONF_CACHE_PATH): cv.string,
vol.Optional(CONF_ALIASES, {}): { cv.string: cv.string }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace after '{'
whitespace before '}'

})

SCAN_INTERVAL = timedelta(seconds=30)
Expand Down Expand Up @@ -89,7 +91,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
configurator = get_component('configurator')
configurator.request_done(hass.data.get(DOMAIN))
del hass.data[DOMAIN]
player = SpotifyMediaPlayer(oauth, config.get(CONF_NAME, DEFAULT_NAME))
player = SpotifyMediaPlayer(oauth, config.get(CONF_NAME, DEFAULT_NAME),
config[CONF_ALIASES])
add_devices([player], True)


Expand Down Expand Up @@ -117,7 +120,7 @@ def get(self, request):
class SpotifyMediaPlayer(MediaPlayerDevice):
"""Representation of a Spotify controller."""

def __init__(self, oauth, name):
def __init__(self, oauth, name, aliases={}):
"""Initialize."""
self._name = name
self._oauth = oauth
Expand All @@ -128,10 +131,11 @@ def __init__(self, oauth, name):
self._image_url = None
self._state = STATE_UNKNOWN
self._current_device = None
self._devices = None
self._devices = {}
self._volume = None
self._shuffle = False
self._player = None
self._aliases = aliases
self._token_info = self._oauth.get_cached_token()

def refresh_spotify_instance(self):
Expand All @@ -156,8 +160,15 @@ def update(self):
# Available devices
devices = self._player.devices().get('devices')
if devices is not None:
self._devices = {device.get('name'): device.get('id')
current_device_keys = self._devices.keys()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local variable 'current_device_keys' is assigned to but never used

self._devices = {self._aliases.get(device.get('id'),
device.get('name')):
device.get('id')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line over-indented for visual indent

for device in devices}
device_diff = {name:id for name, id in self._devices.items()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ':'

if old_devices.get(name, None) is None}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'old_devices'

if len(device_diff) > 0:
_LOGGER.info("New Devices: %s", str(device_diff))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is not a multiple of four

# Current playback state
current = self._player.current_playback()
if current is None:
Expand Down