Skip to content

Spotify aliases#7702

Merged
balloob merged 6 commits into
home-assistant:devfrom
Teagan42:spotify_aliases
Jun 2, 2017
Merged

Spotify aliases#7702
balloob merged 6 commits into
home-assistant:devfrom
Teagan42:spotify_aliases

Conversation

@Teagan42
Copy link
Copy Markdown
Contributor

@Teagan42 Teagan42 commented May 22, 2017

Description:

Spotify some times doesn't respect device names, or just names them terribly. This adds ability to alias the media player instances and logs out new devices to info for ease of aliasing.

Related issue (if applicable): fixes #

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2684

Example entry for configuration.yaml (if applicable):

media_player:
  - platform: spotify
    client_id: <your client id>
    client_secret: <your client secret>
    aliases:
        abc123def456: 'Living Room'
        9183abas000: 'Bed Room'

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable ([example][ex-requir]).
  • New dependencies are only imported inside functions that use them ([example][ex-import]).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

device_diff = {name:id for name, id in self._devices.items()
if old_devices.get(name, None) is None}
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

device.get('id')
for device in devices}
device_diff = {name:id for name, id in self._devices.items()
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'

device.get('name')):
device.get('id')
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 ':'

current_device_keys = self._devices.keys()
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

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

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 '}'

@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented May 29, 2017

What is bad with friendly name on customize?

@happyleavesaoc
Copy link
Copy Markdown
Contributor

@pvizeli This is media player source option friendly names, not entity names

@bieniu
Copy link
Copy Markdown
Member

bieniu commented May 31, 2017

I have error with this PR when HA starts:

2017-05-31 20:01:25 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform spotify
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 155, in _async_setup_platform
    entity_platform.schedule_add_entities, discovery_info
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/media_player/spotify.py", line 95, in setup_platform
    config[CONF_ALIASES])
KeyError: 'aliases'

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
Contributor

Choose a reason for hiding this comment

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

vol.Optional(CONF_ALIASES, default={}) or similar per @bieniu

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@happyleavesaoc With your change the component starts with HA and in log there is information about new device. But when I add this device as an alias in configuration and turn off all Spotify players in log every minute appears this error:

2017-06-01 10:53:17 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.spotify fails Traceback (most recent call last):
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state None, self.update)
File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__ yield self # This tells Task to wait for completion. File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup value = future.result() File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result raise self._exception
File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run result = self.fn(*self.args, **self.kwargs) File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/media_player/spotify.py", line 161, in update devices = self._player.devices().get('devices') AttributeError: 'NoneType' object has no attribute 'get'

And after HA restart there is no Spotify component at all but only error:

2017-06-01 10:39:29 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Traceback (most recent call last):
File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step result = coro.throw(exc) File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 361, in async_process_entity new_entity, self, update_before_add=update_before_add
File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 191, in async_add_entity yield from self.hass.loop.run_in_executor(None, entity.update)
File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__ yield self # This tells Task to wait for completion. File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup value = future.result() File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result raise self._exception
File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run result = self.fn(*self.args, **self.kwargs) File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/media_player/spotify.py", line 161, in update devices = self._player.devices().get('devices') AttributeError: 'NoneType' object has no attribute 'get'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a None check and the default try the most recent commit.

@Teagan42
Copy link
Copy Markdown
Contributor Author

Teagan42 commented Jun 1, 2017 via email

@balloob balloob merged commit cefacf9 into home-assistant:dev Jun 2, 2017
@balloob balloob mentioned this pull request Jun 2, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Sep 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants