Skip to content

Refuse a Connect entity of another account and retry transfers on 404 - #77

Merged
Mincka merged 1 commit into
mainfrom
fix/76-connect-entity-account-mismatch
Sep 22, 2026
Merged

Mincka merged 1 commit into
mainfrom
fix/76-connect-entity-account-mismatch

Conversation

@Mincka

@Mincka Mincka commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Description

A *_spotcast media player mirrors a Spotify Connect device as seen by one Spotcast account. The device is signed in to that account only, so a play or transfer from another account gets a 404 from Spotify. Spotcast accepted the entity regardless, waited 12 seconds for the device to appear and gave up with "not available on Spotify Connect", or, on the transfer path, surfaced spotipy's raw "Device not found". That is what the reporter of #76 hit with two accounts and one Chromecast.

This PR:

  • Refuses a Connect entity of another account right away. async_build_from_type checks that the SpotifyDevice belongs to the calling account and raises the new AccountMismatchError, whose message names both accounts and points at the Google Cast entity (the only route that can switch a device between accounts). play_media and play_custom_context report it as a ServiceValidationError, like a missing active device.
  • Retries a transfer on 404. The transfer branch of async_play_media now gets the same wait-and-retry as the start branch, since a Chromecast whose Spotify app was just relaunched can still be registering. The timeout message names the account.
  • Fixes the invalid entity id Home Assistant flagged in the same log (media_player.cloudytv_koen.wigman-nl_spotcast). _define_entity_id slugifies the whole identity key. The key itself is unchanged, so unique ids, device identifiers and the legacy migration are untouched and registered entities keep their entity id.
  • Documents in the README and the play_media / transfer_playback docs that a *_spotcast entity only works with its own account.

Refs #76 (kept open until the reporter confirms the Google Cast route works for them).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented on my code where necessary
  • I have added tests that are covering all code branches
  • New and existing unit tests pass locally with my changes

Additional Information

  • 840 tests pass locally, pylint 10.00/10.
  • New tests: other-account guard and message (test_async_build_from_type.py), the account property, ServiceValidationError mapping in both services, transfer 404 retry / timeout / non-404 paths, and entity ids for account ids with . and -.
  • Not in scope: auto-routing a foreign *_spotcast entity to a same-named Google Cast device. The reporter now targets the cast entity directly; a clear error plus docs is the cleaner answer for everyone else.

🤖 Generated with Claude Code

A `*_spotcast` media player mirrors a Spotify Connect device as seen by
one Spotcast account. The device is signed in to that account only, so
a play or transfer from another account gets a 404 from Spotify. Spotcast
accepted the entity regardless, waited 12 seconds for the device to show
up and gave up with "not available on Spotify Connect", or, on the
transfer path, surfaced spotipy's raw "Device not found" (#76).

async_build_from_type now checks that the entity belongs to the calling
account and raises AccountMismatchError with a message that names both
accounts and points at the Google Cast entity, which is the only route
that can switch a device between accounts. play_media and
play_custom_context report it as a ServiceValidationError.

The transfer branch of async_play_media gets the same 404 wait-and-retry
as the start branch, since a Chromecast whose Spotify app was just
relaunched can still be registering. The timeout message now names the
account.

The same log showed Home Assistant flagging an invalid entity id built
from an account id containing a dot and a dash. _define_entity_id now
slugifies the whole identity key. The key itself is unchanged, so unique
ids, device identifiers and the legacy migration are untouched and
registered entities keep their entity id.

Refs #76

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Mincka
Mincka merged commit c31bb03 into main Sep 22, 2026
7 checks passed
@Mincka
Mincka deleted the fix/76-connect-entity-account-mismatch branch September 22, 2026 20:44
@Mincka Mincka mentioned this pull request Sep 22, 2026
7 of 9 tasks
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.

1 participant