Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard browsing Spotify if setup failed #65074

Merged
merged 2 commits into from Jan 27, 2022

Conversation

jjlawren
Copy link
Contributor

Proposed change

If Spotify is configured but hasn't successfully loaded it can lead to errors when browsing from another integration (e.g., Sonos).

File "/usr/src/homeassistant/homeassistant/components/sonos/media_player.py", line 698, in async_browse_media
    return await media_browser.async_browse_media(
File "/usr/src/homeassistant/homeassistant/components/sonos/media_browser.py", line 109, in async_browse_media
    return await spotify.async_browse_media(hass, None, None, can_play_artist=False)
File "/usr/src/homeassistant/homeassistant/components/spotify/__init__.py", line 63, in async_browse_media
    info = list(hass.data[DOMAIN].values())[0]
KeyError: 'spotify'

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @frenck, mind taking a look at this pull request as it has been labeled with an integration (spotify) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@jjlawren jjlawren added this to the 2022.2.0 milestone Jan 27, 2022
@jjlawren jjlawren requested a review from balloob January 27, 2022 18:34
info = list(hass.data[DOMAIN].values())[0]
info = next(iter(hass.data[DOMAIN].values()), None)
if not info:
raise BrowseError("No Spotify accounts available")
Copy link
Member

Choose a reason for hiding this comment

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

Should we catch this inside Sonos?

Copy link
Member

Choose a reason for hiding this comment

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

I think this makes a lot of sense to do here, mainly because anything else can just use it without having to worry about it.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I meant catch BrowseError in Sonos. The check here is indeed correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that's necessary. It should only hit this codepath if the browser is explicitly trying to browse into Spotify. It'll only hit this at the root level is Spotify is the only source available.

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
@balloob balloob merged commit 5a4eeae into home-assistant:dev Jan 27, 2022
balloob pushed a commit that referenced this pull request Jan 27, 2022
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
@github-actions github-actions bot locked and limited conversation to collaborators Jan 28, 2022
@jjlawren jjlawren deleted the spotify_guard_setup_failure branch May 31, 2022 17:41
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.

None yet

4 participants