-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Spotify aliases #7702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spotify aliases #7702
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
|
|
@@ -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 } | ||
| }) | ||
|
|
||
| SCAN_INTERVAL = timedelta(seconds=30) | ||
|
|
@@ -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) | ||
|
|
||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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): | ||
|
|
@@ -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() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing whitespace after ':' |
||
| if old_devices.get(name, None) is None} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace after '{'
whitespace before '}'