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

+28 -2
View File
@@ -26,14 +26,28 @@ MODEL = os.environ.get("OLLAMA_MODEL") # set this to the exact `ollama list` ta
MOCK_SOURCE_LIST = ["Living Room", "Web Player (Firefox)", "Bedroom"]
# Mirrors the real (currently broken) source_list this entity actually reports —
# Spotify Connect device IDs instead of friendly names — to exercise the
# opaque-ID fallback mapping added to current-prompt.txt's Room section.
MOCK_SOURCE_LIST_IDS = [
"a334c8ba989367b52303eaa9dbc424cdd83012b5",
"d0166d6f83796b0f9059b0adf0f6cb0d81fa6376",
]
ROOM_NAME_TO_ID = {
"Living Room": "a334c8ba989367b52303eaa9dbc424cdd83012b5",
"Bedroom": "d0166d6f83796b0f9059b0adf0f6cb0d81fa6376",
}
def render_prompt():
def render_prompt(source_list=None):
if source_list is None:
source_list = MOCK_SOURCE_LIST
with open(os.path.join(HERE, "current-prompt.txt")) as f:
raw = f.read()
def state_attr(entity_id, attr):
if entity_id == "media_player.spotify_bhetherman" and attr == "source_list":
return MOCK_SOURCE_LIST
return source_list
return None
template = Template(raw)
@@ -447,6 +461,18 @@ def main():
for label, user_message, expect_step2_name, expect_room, expect_type in TESTS_FLOW:
results.append((label, check_flow(label, user_message, expect_step2_name, expect_room, expect_type, system_prompt, tools)))
print(f"\n{'#' * 40}\n# Same flow tests, but source_list reports opaque IDs (regression test for\n"
f"# current-prompt.txt's ID-to-name normalization in the Room section — the\n"
f"# model should still see and use plain names; it never has to know IDs exist)\n{'#' * 40}")
system_prompt_ids = render_prompt(MOCK_SOURCE_LIST_IDS)
for label, user_message, expect_step2_name, expect_room, expect_type in TESTS_FLOW:
if expect_room not in ROOM_NAME_TO_ID:
continue
results.append((
f"{label} [opaque-ID rooms]",
check_flow(label, user_message, expect_step2_name, expect_room, expect_type, system_prompt_ids, tools),
))
total_passed = sum(passed for _, (passed, n) in results)
total_attempts = sum(n for _, (passed, n) in results)
reliable = [label for label, (passed, n) in results if passed == n]