8000 Rewrite of Spotify integration by frenck · Pull Request #30717 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Rewrite of Spotify integration #30717

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

Merged
merged 28 commits into from
Jan 24, 2020
Merged

Rewrite of Spotify integration #30717

merged 28 commits into from
Jan 24, 2020

Conversation

frenck
Copy link
Member
@frenck frenck commented Jan 12, 2020

Breaking Change:

The Spotify platform has been rewritten to an integration. The configuration has been changed. Removing the current Spotify platform and setting up the integration from scratch is recommended.

The device aliases and the spotify.play_playlist service, have been removed. Be sure to remove calls to that service from your automations.

If you use the Spotify platform at this moment:

  • Remove the current configuration from your configuration.yaml file.
  • Remove the .spotify-token-cache file from your configuration directory. It is no longer used, however, it does contain security credentials.
  • Follow the documentation on how to set up the new Spotify integration from scratch.

Description:

I figured Spotify is probably something people use a lot. It works but could be better. A good excuse for me to play with OAuth2 in Home Assistant 😉

2020-01-12 22 25 26

image

Changes:

  • Rewrites platform to an integration
  • Adds config flow
  • Implements OAuth 2 helpers/flow
  • Discovery of an active Spotify Connect on the network
  • Uses the original (newer) Spotify package, instead of a fork.
  • Removes the old configurator
  • Support for Spotify Free & Open accounts
  • Added SEEK capabilities (including current media position)
  • Added support for the playlist title attribute
  • Added support for track number attribute
  • Removed device alias support
  • Removed spotify.play_playlist_service, use media_player.play_media (using media_content_type = playlist) instead.

Still to work on:

  • Write tests
    • config_flow 🥇
    • __init__ 🥇
    • media_player 🥇
  • Resolution of architectural proposal Allow for a more dynamic supported_features architecture#338
  • Raise PlatformNotReady if unable to connect during platform setup 🥈
  • Handle being offline/unavailable correctly 🥈
  • Set available property to False if appropriate 🥈
  • Supports entities being disabled 🥇
  • Remove some minor log spam
  • Test to find out if we can make it useable for non-premium users somewhat
  • General cleanup and prettify everything 😉
  • Fix hassfest to know this flow is actual valid (Fix hassfest allowing omitting discovery methods when using OAuth2Flow #30732)
  • Extend Breaking change description
  • Update documentation

Related issue (if applicable): fixes #27139

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#11858

Example entry for configuration.yaml (if applicable):

spotify:
  client_id: CLIENT_ID
  client_secret: CLIENT_SECRET

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

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

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

  • The manifest file has all fields filled out correctly. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

Copy link
Member
@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Nice start!

@Ahoui-group
Copy link
Ahoui-group commented Jan 14, 2020

Great progress! Hope we maintain the ability to have multiple spotify accounts in HA as the current implementation provides. I would guess the multiple instances of '.spotify_xxxx' files will no longer be needed.

@frenck
Copy link
Member Author
frenck commented Jan 14, 2020

@Ahoui-group Yes, it supports multiple accounts. Cache files are no longer needed and not used.

@dshokouhi
Copy link
Member

Wasn't 100% sure if it was in the code but will this also import existing configuration? Given it is updated to the new format?

@frenck
Copy link
Member Author
frenck commented Jan 17, 2020

@dshokouhi No, it won't, you have to re-add/re-auth.
The authentication handling is being moved and the whole thing is moving from a platform to an integration.

@Electronlibre2012
Copy link

good work @frenck ! wait for it! 👍

@Electronlibre2012
Copy link
Electronlibre2012 commented Jan 18, 2020

Sorry to ask but @frenck when do you think it would be released please?

I m hoping it was already on the 0.104.2 of yesterday lol ... cant wait for it ;)

@frenck
Copy link
Member Author
frenck commented Jan 18, 2020

@Electronlibre2012 This re-write introduces new features and will not be released with a bug fix release. I'm currently aiming for 0.105, however, there is no warranty it will make that release.

@Electronlibre2012
Copy link

thanks,

ok...we have to wait...

@fondberg
Copy link

@frenck Great that you picked this up!
I maintain a custom component called spotcast which I really want to kill in favor of this, however it is currently not possible.
In order to do that the Spotify platform would need to support a more powerful token when starting chromecast which today means that the token needs to be fetched as if it was the webplayer (browser based login) which is done using the spotify_token python library or having the client id used in the oath flow being elevated by Spotify. The latter is preferable but it would mean that it needs to be an official integration. I ran this by @balloob last year and he thought it could be something for Nabu Casa to have an official integration with Spotify which the Nabu Casa users could benefit from.
If there is anything I can help with (I have quite a lot of Spotify knowledge), please don't shout.

@balloob
Copy link
Member
balloob commented Jan 19, 2020

OAuth2 via our account linking service is still the plan and it's possible with the OAuth2 helpers that Frenck has implemented in this PR.

@fondberg
Copy link

That is great to hear!

frenck added 21 commits January 24, 2020 16:54
@frenck
Copy link
Member Author
frenck commented Jan 24, 2020

ℹ️ Rebased PR onto latest dev.

)

# pylint: disable=protected-access
state = config_entry_oauth2_flow._encode_jwt(hass, {"flow_id": result["flow_id"]})
Copy link
Member

Choose a reason for hiding this comment

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

Can we patch this encode function instead so we don't need to disable the pylint warning?

Copy link
Member Author
@frenck frenck Jan 24, 2020

Choose a reason for hiding this comment

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

I guess that will be unneeded hard since it has to be valid later on.
Followed the implementation by Paulus in Somfy for this.

IMHO, patching or using private methods are equally bad though 🤷‍♂

I added the pylint disable, because well, I think it is nice to do, I can simply remove it since we don't run it on tests.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. We should keep the disable so that editor linters and lazytox don't complain.

Copy link
Member

Choose a reason for hiding this comment

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

In my opinion we should lint tests too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally agree! I lint my tests, but it has never been done @ HA. The amount of linter warnings is insane right now.

Copy link
Member
@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good!

@frenck frenck merged commit 7e4b9ad into dev Jan 24, 2020
@frenck frenck deleted the frenck-2020-0067 branch January 24, 2020 17:47
@lock lock bot locked and limited conversation to collaborators Jan 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4B4B
Development

Successfully merging this pull request may close these issues.

Multiple spotify instances not working
9 participants
0