Skip to content

Retry the setup when Spotify is unreachable at startup - #93

Merged
Mincka merged 1 commit into
mainfrom
fix/setup-not-ready-on-network-errors
Nov 27, 2026
Merged

Mincka merged 1 commit into
mainfrom
fix/setup-not-ready-on-network-errors

Conversation

@Mincka

@Mincka Mincka commented Nov 27, 2026

Copy link
Copy Markdown
Owner

If Spotify cannot be reached while Home Assistant starts, the Spotcast entry ends up in setup_error and stays there. Home Assistant does not retry it, so every spotcast.* action fails with "Action spotcast.play_media not found" until the entry is reloaded by hand or Home Assistant restarts.

async_setup_entry only turned InternalServerError into ConfigEntryNotReady. Everything else raised while building the account was treated as a permanent failure:

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.

Tests

  • test/test_is_transient_setup_error.py: 15 transient and 10 permanent errors
  • test/test_async_setup_entry.py: setup raises ConfigEntryNotReady for 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 on main.
  • 868 unit tests pass, pylint 10.00/10

Live check (Home Assistant 2026.11.3)

With api.spotify.com and accounts.spotify.com unreachable from the Home Assistant container, reloading the entry put it in setup_retry with "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 sensor ok, devices listed.

Fixes #92

🤖 Generated with Claude Code

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]>
@Mincka
Mincka merged commit 780bf7c into main Nov 27, 2026
7 checks passed
@Mincka
Mincka deleted the fix/setup-not-ready-on-network-errors branch November 27, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Entry stays in setup_error after a network timeout during startup (no ConfigEntryNotReady)

1 participant