home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.79k stars 30.49k forks source link

Setting Spotify source from script does not work while setting it on the UI does. #129122

Open distante opened 1 day ago

distante commented 1 day ago

The problem

I am having problems making Spotify to choose a source from a script.

I have this:

play_spotify_de_saninn_en_wohnzimmer:
  alias: Play Spotify de Saninn en Wohnzimmer
  sequence:
    - action: media_player.select_source
      data:
        source: "Radio Wohnzimmer"
      target:
        entity_id: media_player.spotify_saninn
  description: ""
  icon: mdi:account-music

Calling the script does not fails but also does nothing.

If I select the source from the extension UI It sets the source and turns on the media device as expected. image

What version of Home Assistant Core has the issue?

core-2024.10.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Spotify

Link to integration documentation on our website

https://www.home-assistant.io/integrations/spotify/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

In the logs I see that the script call GETs the info about the player but never updates it. While the UI does a PUT at the end.

Script call logs:

2024-10-25 08:12:12.060 DEBUG (SyncWorker_29) [spotipy.client] Sending GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} Headers: {'Authorization': 'Bearer My-Token', 'Content-Type': 'application/json'} and Body: None 
2024-10-25 08:12:12.096 DEBUG (SyncWorker_29) [spotipy.client] RESULTS: None
2024-10-25 08:12:12.097 DEBUG (MainThread) [homeassistant.components.spotify.coordinator] Finished fetching spotify data in 0.037 seconds (success: True)
2024-10-25 08:12:12.242 DEBUG (SyncWorker_30) [spotipy.client] Sending GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} Headers: {'Authorization': 'Bearer My-Token', 'Content-Type': 'application/json'} and Body: None 
2024-10-25 08:12:12.278 DEBUG (SyncWorker_30) [spotipy.client] RESULTS: None
2024-10-25 08:12:12.279 DEBUG (MainThread) [homeassistant.components.spotify.coordinator] Finished fetching spotify data in 0.037 seconds (success: True)
2024-10-25 08:12:12.387 DEBUG (SyncWorker_4) [spotipy.client] Sending GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} Headers: {'Authorization': 'Bearer My-Token', 'Content-Type': 'application/json'} and Body: None 
2024-10-25 08:12:12.420 DEBUG (SyncWorker_4) [spotipy.client] RESULTS: None
2024-10-25 08:12:12.422 DEBUG (MainThread) [homeassistant.components.spotify.coordinator] Finished fetching spotify data in 0.036 seconds (success: True)

UI Call logs:

2024-10-25 08:20:12.060 DEBUG (SyncWorker_33) [spotipy.client] Sending GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} Headers: {'Authorization': 'Bearer My-Token', 'Content-Type': 'application/json'} and Body: None 
2024-10-25 08:20:12.094 DEBUG (SyncWorker_33) [spotipy.client] RESULTS: None
2024-10-25 08:20:12.095 DEBUG (MainThread) [homeassistant.components.spotify.coordinator] Finished fetching spotify data in 0.036 seconds (success: True)
2024-10-25 08:20:12.241 DEBUG (SyncWorker_34) [spotipy.client] Sending GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} Headers: {'Authorization': 'Bearer My-Token, 'Content-Type': 'application/json'} and Body: None 
2024-10-25 08:20:12.276 DEBUG (SyncWorker_34) [spotipy.client] RESULTS: None
2024-10-25 08:20:12.277 DEBUG (MainThread) [homeassistant.components.spotify.coordinator] Finished fetching spotify data in 0.036 seconds (success: True)
2024-10-25 08:20:12.388 DEBUG (SyncWorker_23) [spotipy.client] Sending GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} Headers: {'Authorization': 'Bearer My-Token', 'Content-Type': 'application/json'} and Body: None 
2024-10-25 08:20:12.423 DEBUG (SyncWorker_23) [spotipy.client] RESULTS: None
2024-10-25 08:20:12.424 DEBUG (MainThread) [homeassistant.components.spotify.coordinator] Finished fetching spotify data in 0.036 seconds (success: True)
2024-10-25 08:20:21.634 DEBUG (SyncWorker_63) [spotipy.client] Sending PUT to https://api.spotify.com/v1/me/player with Params: {} Headers: {'Authorization': 'Bearer My-Token', 'Content-Type': 'application/json'} and Body: '{"device_ids": ["ba70685b66343e4cafd04efc6ab1c526f29afafc"], "play": false}' 
2024-10-25 08:20:21.943 DEBUG (SyncWorker_63) [spotipy.client] RESULTS: None

Additional information

No response

home-assistant[bot] commented 1 day ago

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

Code owner commands Code owners of `spotify` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign spotify` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


spotify documentation spotify source (message by IssueLinks)