Repository navigation
Retry the setup when Spotify is unreachable at startup - #93
Merged
Merged
Conversation
async_setup_entry only turned InternalServerError into ConfigEntryNotReady. Any other network failure while building the account left the entry in setup_error, and Home Assistant never retried it: every spotcast action failed with "Action not found" until a manual reload or a restart. That covered a read timeout or a DNS/connection error on the profile call (the case in #92), but also the token endpoint being unreachable (UpstreamServerNotready, raised by the session refresh), aiohttp timeouts, and spotipy giving up on 5xx or 429 responses. is_transient_setup_error now decides what is worth a retry: network failures and errors whose http status is 429 or 5xx. Other statuses (401, 403, 404) still surface as a setup error so a real auth problem does not loop through ConfigEntryNotReady. The base list reuses RetrySupervisor.SUPERVISED_EXCEPTIONS, as the coordinator already does. Verified live on Home Assistant 2026.11.3: with api.spotify.com and accounts.spotify.com unreachable, reloading the entry put it in setup_retry (it went to setup_error before); once they were reachable again Home Assistant set it up on its own 5 s later, with the services registered and the sensors back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 27, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If Spotify cannot be reached while Home Assistant starts, the Spotcast entry ends up in
setup_errorand stays there. Home Assistant does not retry it, so everyspotcast.*action fails with "Action spotcast.play_media not found" until the entry is reloaded by hand or Home Assistant restarts.async_setup_entryonly turnedInternalServerErrorintoConfigEntryNotReady. Everything else raised while building the account was treated as a permanent failure:UpstreamServerNotready, which was not caught either, and it is the first network call of the setupis_transient_setup_errornow decides what is worth a retry: network failures, and errors whose http status is 429 or 5xx. Other statuses (401, 403, 404) still surface as a setup error, so a real auth problem does not loop throughConfigEntryNotReady. The base list reusesRetrySupervisor.SUPERVISED_EXCEPTIONS, as the coordinator already does.Tests
test/test_is_transient_setup_error.py: 15 transient and 10 permanent errorstest/test_async_setup_entry.py: setup raisesConfigEntryNotReadyfor the Entry stays in setup_error after a network timeout during startup (no ConfigEntryNotReady) #92 read timeout, a DNS failure, the token endpoint being unreachable, an aiohttp timeout and spotipy's fake 429, plus a timeout during the token check; a 403 still propagates. The 6 network cases fail onmain.Live check (Home Assistant 2026.11.3)
With
api.spotify.comandaccounts.spotify.comunreachable from the Home Assistant container, reloading the entry put it insetup_retrywith "Spotify is unreachable, setup will be retried: ... /v1/me/ ... Connection refused". Once the hosts were reachable again, Home Assistant set the entry up on its own 5 s later: 10 services registered, profile sensorok, devices listed.Fixes #92
🤖 Generated with Claude Code