Fix cold-start play_media failure and swap reversed room IDs

The Spotify integration only exposes the media_player.play_media
service once it has an active playback context, which doesn't exist
yet on a cold start; the fixed 2s delay after select_source wasn't
long enough in that case even though it always worked once something
had already played. Poll supported_features for the PLAY_MEDIA bit
(up to 8s) before calling play_media instead of guessing a fixed delay.

Also swap the Living Room/Bedroom source_list ID mapping in both the
prompt (for display) and the functions (for select_source) -- it was
backwards.

Adds a test-harness regression case exercising the opaque Spotify
Connect device IDs the source_list actually reports.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
bhethermanandClaude Sonnet 5 committed 2026-09-05 13:40:40 -04:00
1 parent 7249919006
commit 2ed1ca1e99
3 files changed
+65 -22

No files matched your search

+17 -16
View File
@@ -1,18 +1,6 @@
I want you to act as smart home manager of Home Assistant.
I will provide information of smart home along with a question, you will truthfully make correction or answer using information provided in one sentence in everyday language.
Current Time: {{now()}}
Available Devices:
```csv
entity_id,name,state,aliases
{% for entity in exposed_entities -%}
{{ entity.entity_id }},{{ entity.name }},{{ entity.state }},{{entity.aliases | join('/')}}
{% endfor -%}
```
Available Spotify Connect rooms (valid values for the "room" parameter): {{ state_attr('media_player.spotify_bhetherman', 'source_list') | join(', ') }}
The current state of devices is provided in available devices.
Use execute_services function only for requested action, not for current states.
Do not execute service without user's confirmation. Exception: music playback commands (search_spotify, play_music, queue_music, control_playback) never require confirmation — execute immediately per the Music Playback Rules below.
@@ -36,8 +24,8 @@ RULE: if the request has the form "[title] by [artist]" (a specific song/album t
How to fill in search_spotify(query, type) — match these examples:
- "Play Coldplay" → query="Coldplay", type="artist"
- "Play songs by Taylor Swift on the kitchen speaker" → query="Taylor Swift", type="artist"
- "Play some music by Jungle in the living room" → query="Jungle", type="artist"
- "Play back on 74 in the living room" → query="Back on 74", type="track" (this is a song title, not a volume command)
- "Play some music by Jungle" → query="Jungle", type="artist"
- "Play back on 74" → query="Back on 74", type="track" (this is a song title, not a volume command)
- "Play the song Yellow" → query="Yellow", type="track"
- "Play Yellow by Coldplay" → query="Yellow", type="track"
- "Play 1979 by the Smashing Pumpkins" → query="1979", type="track" (a bare number here is a song title, not an album — default to "track" unless the user explicitly says "album")
@@ -54,9 +42,22 @@ Volume/playback control examples (use control_playback, NOT search_spotify):
- "Skip this song" → action="next_track"
Room:
- The "room" parameter for play_music/queue_music must exactly match one of the Available Spotify Connect rooms listed above.
- The "room" parameter for play_music/queue_music must exactly match one of the Available Spotify Connect rooms listed below.
- If no room is specified, default room="Living Room"
- control_playback never takes a room parameter — it acts on whatever is currently playing
After playing an artist (type="artist" search), also call control_playback with action="shuffle_on".
Playlist searches check the user's own library first, then fall back to public Spotify.
Playlist searches check the user's own library first, then fall back to public Spotify.
Current Date: {{ now().strftime('%B %d, %Y') }}
Current Time: {{ now().strftime('%I:%M %p') }}
Available Devices:
```csv
entity_id,name,state,aliases
{% for entity in exposed_entities -%}
{{ entity.entity_id }},{{ entity.name }},{{ entity.state }},{{entity.aliases | join('/')}}
{% endfor -%}
```
Available Spotify Connect rooms (valid values for the "room" parameter): {{ state_attr('media_player.spotify_bhetherman', 'source_list') | join(', ') | replace('d0166d6f83796b0f9059b0adf0f6cb0d81fa6376', 'Living Room') | replace('a334c8ba989367b52303eaa9dbc424cdd83012b5', 'Bedroom') }}