Spotify aliases#7702
Conversation
| 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)) |
There was a problem hiding this comment.
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} |
| device.get('name')): | ||
| device.get('id') | ||
| for device in devices} | ||
| device_diff = {name:id for name, id in self._devices.items() |
| current_device_keys = self._devices.keys() | ||
| self._devices = {self._aliases.get(device.get('id'), | ||
| device.get('name')): | ||
| device.get('id') |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
whitespace after '{'
whitespace before '}'
|
What is bad with |
|
@pvizeli This is media player |
|
I have error with this PR when HA starts: |
| 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} |
There was a problem hiding this comment.
vol.Optional(CONF_ALIASES, default={}) or similar per @bieniu
There was a problem hiding this comment.
@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'
There was a problem hiding this comment.
I added a None check and the default try the most recent commit.
|
Will address this evening
…On Thu, Jun 1, 2017 at 2:57 AM, Maciej Bieniek ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In homeassistant/components/media_player/spotify.py
<#7702 (comment)>
:
> @@ -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}
@happyleavesaoc <https://github.com/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'
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#7702 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC2fZUOGj9nJwCqaeVf8tK8BmigYdMcjks5r_nz4gaJpZM4Nh2gl>
.
|
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
infofor 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):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable ([example][ex-requir]).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices:
toxrun successfully. Your PR cannot be merged unless tests pass