fondberg / spotcast

Home assistant custom component to start Spotify playback on an idle chromecast device as well as control spotify connect devices
Apache License 2.0
672 stars 96 forks source link

Automation fails when calling spotcast.start to sleeping device #419

Closed dennisgranasen closed 8 months ago

dennisgranasen commented 8 months ago

Bug Ticket

Describe the bug

Automation calling spotcast.start fails when target device is sleeping. It seems to run fine when activated again moments later. Verified using a Harman Kardon Citation Oasis with CC built-in.

Troubleshooting

Make sure to validate all the elements before submitting the ticket (Exception to the steps marked as optional)

Environment

Configuration

# please remove any sensitive information like cookies and token keys
spotcast:
  sp_dc: !secret sp_dc
  sp_key: !secret sp_key

Service Call

alias: Good morning
description: ""
trigger:
  - platform: time
    at: input_datetime.wake_up_time
condition:
  - condition: state
    entity_id: calendar.sweden
    state: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 0
    enabled: true
action:
  - service: spotcast.start
    metadata: {}
    data:
      limit: 20
      repeat: "off"
      offset: 0
      entity_id: media_player.hk_citation_oasis_abc123
      uri: spotify:playlist:<uri to my playlist>
      random_song: true
      start_volume: 22
mode: single

Logs

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 669, in async_trigger
    await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1587, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 426, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 479, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 502, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 476, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 713, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 675, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2193, in _execute_service
    return await self._hass.async_add_executor_job(target, service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/spotcast/__init__.py", line 221, in start_casting
    spotify_device_id = spotcast_controller.get_spotify_device_id(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/spotcast/spotcast_controller.py", line 301, in get_spotify_device_id
    spotify_cast_device.start_spotify_controller(access_token, expires)
  File "/config/custom_components/spotcast/spotcast_controller.py", line 104, in start_spotify_controller
    sp.launch_app()
  File "/config/custom_components/spotcast/spotify_controller.py", line 110, in launch_app
    raise LaunchError(
pychromecast.error.LaunchError: Timeout when waiting for status response from Spotify app

Additional context

N/A

dennisgranasen commented 8 months ago

I just realized this is probably the same error as #249