Open hmmbob opened 3 years ago
Further to the issue above, this issue does not only occur with Spotcast, but also with custom scripts to stream webradio streams to Google cast devices. The error log and outcome is identical as above. The only service that does not seem to be affected is the custom Youtube Music player.
Kind regards
Hello,
when spotify it start from my smartphone, and a googlehome selected, all works and the information of playing in HA works, can control volume and see what song is played, the problem is only to start cast, it doesnt work anymore. Hope developper will find a solution in the next update ;)
I could be wrong here, but it looks like maybe the spotify chromecast protocol might have changed?
I get this log
Sending: Message urn:x-cast:com.spotify.chromecast.secure.v1 from sender-0 to f658741b-e343-47be-b186-3e87fa255537: {'type': 'setCredentials' ...}
But do not seem to see any logs with the response the code is expecting https://github.com/home-assistant-libs/pychromecast/blob/master/pychromecast/controllers/spotify.py#L42
Put a pr together that seems to work for me.
https://github.com/home-assistant-libs/pychromecast/pull/521
Are there maybe two separate things going on here:
@XalaTheShepard could you please open a new issue and share your script which previously worked but no longer doesn't?
@emontnemery, this issue surfaced again recently.
Yes, indeed it did.
2023-09-03 20:35:06.439 ERROR (Thread-15) [pychromecast.socket_client] [(192.168.88.113):8009] Exception caught while sending message to controller SpotifyController: Message urn:x-cast:com.spotify.chromecast.secure.v1 from 540d6d97-a77a-4043-a45b-42cf5ba5f411 to sender-0: {'type': 'getInfoResponse', 'payload': {'version': '2.9.0', 'publicKey': 'empty', 'remoteName': 'Spotify on Cast', 'deviceType': 'cast_audio', 'brandDisplayName': 'google', 'modelDisplayName': 'Google_Home', 'libraryVersion': '5.30.3', 'resolverVersion': '1', 'groupStatus': 'NONE', 'deviceAPI_isGroup': False, 'tokenType': 'accesstoken', 'clientID': 'd7df0887fb71494ea994202cb473eae7', 'productID': 0, 'scope': 'streaming', 'availability': '', 'spotifyError': 0, 'status': 101, 'statusString': 'OK'}}
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/pychromecast/socket_client.py", line 719, in _route_message
handled = handler.receive_message(message, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/spotify_controller.py", line 47, in receive_message
self.device = data["payload"]["deviceID"]
~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'deviceID'
2023-09-03 20:35:15.157 ERROR (MainThread) [homeassistant.components.script.start_music_t] Slaaptijd: Error executing script. Unexpected error for call_service at pos 2: Timeout when waiting for status response from Spotify app
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 467, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 703, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 665, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 1963, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2007, 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 250, in get_spotify_device_id
spotify_cast_device.startSpotifyController(access_token, expires)
File "/config/custom_components/spotcast/spotcast_controller.py", line 95, in startSpotifyController
sp.launch_app()
File "/config/custom_components/spotcast/spotify_controller.py", line 104, in launch_app
raise LaunchError(
pychromecast.error.LaunchError: Timeout when waiting for status response from Spotify app
2023-09-03 20:35:15.165 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 596, in _async_run
return await self.script.async_run(script_vars, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1570, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 419, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 469, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 492, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 467, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 703, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 665, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 1963, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2007, 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 250, in get_spotify_device_id
spotify_cast_device.startSpotifyController(access_token, expires)
File "/config/custom_components/spotcast/spotcast_controller.py", line 95, in startSpotifyController
sp.launch_app()
File "/config/custom_components/spotcast/spotify_controller.py", line 104, in launch_app
raise LaunchError(
pychromecast.error.LaunchError: Timeout when waiting for status response from Spotify app
2023-09-03 20:35:40.585 ERROR (Thread-16) [pychromecast.socket_client] [(192.168.88.113):8009] Exception caught while sending message to controller SpotifyController: Message urn:x-cast:com.spotify.chromecast.secure.v1 from 31288e75-ec9c-42e9-bd9b-008994b003c7 to sender-0: {'type': 'getInfoResponse', 'payload': {'version': '2.9.0', 'publicKey': 'empty', 'remoteName': 'Spotify on Cast', 'deviceType': 'cast_audio', 'brandDisplayName': 'google', 'modelDisplayName': 'Google_Home', 'libraryVersion': '5.30.3', 'resolverVersion': '1', 'groupStatus': 'NONE', 'deviceAPI_isGroup': False, 'tokenType': 'accesstoken', 'clientID': 'd7df0887fb71494ea994202cb473eae7', 'productID': 0, 'scope': 'streaming', 'availability': '', 'spotifyError': 0, 'status': 101, 'statusString': 'OK'}}
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/pychromecast/socket_client.py", line 719, in _route_message
handled = handler.receive_message(message, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/spotify_controller.py", line 47, in receive_message
self.device = data["payload"]["deviceID"]
~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'deviceID'
2023-09-03 20:35:46.751 ERROR (MainThread) [homeassistant.components.script.start_music_t] Slaaptijd: Error executing script. Unexpected error for call_service at pos 2: Timeout when waiting for status response from Spotify app
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 467, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 703, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 665, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 1963, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2007, 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 250, in get_spotify_device_id
spotify_cast_device.startSpotifyController(access_token, expires)
File "/config/custom_components/spotcast/spotcast_controller.py", line 95, in startSpotifyController
sp.launch_app()
File "/config/custom_components/spotcast/spotify_controller.py", line 104, in launch_app
raise LaunchError(
pychromecast.error.LaunchError: Timeout when waiting for status response from Spotify app
2023-09-03 20:35:46.757 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 596, in _async_run
return await self.script.async_run(script_vars, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1570, in async_run
return await asyncio.shield(run.async_run())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 419, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 469, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 492, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 467, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 703, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 665, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 1963, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2007, 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 250, in get_spotify_device_id
spotify_cast_device.startSpotifyController(access_token, expires)
File "/config/custom_components/spotcast/spotcast_controller.py", line 95, in startSpotifyController
sp.launch_app()
File "/config/custom_components/spotcast/spotify_controller.py", line 104, in launch_app
raise LaunchError(
pychromecast.error.LaunchError: Timeout when waiting for status response from Spotify app
Actually the one surfaced now is different from the old one. The response from the Spotify app on the cast device does not contain the deviceID
what Spotcast utilising to get the accesstoken
from the desktop player API, so Spotcast is unable to take control of the Spotify cast, so pychromecast
times out. It is the case when the device is idle. If the device is already playing something, then the response from the Spotify app contains the deviceID
and there isn't any error.
My guess it is an upstream change in how the Spotify app behaves on the cast device, as it used to provide the deviceID
, but not anymore.
As it is beyond my understanding, I am not sure, why the deviceID
is not provided anymore. Is it pychromecast initiating the Spotify app incorrectly, or what is causing it? But what is sure, that the Spotify app starts on the cast device, as it sends an info response, but why isn't any deviceID
assigned is a good question.
When using Spotcast, pychromecast fails to start spotify playback. The 'connection tone' on the chosen speaker plays but the item is not started, while the following
pychromecast
error is thrown:Based on the error, it appears to be an issue with
pychromecast
instead of Spotcast, hence why I am raising this here.More info at Spotcast repo: https://github.com/fondberg/spotcast/issues/241 (including some initial thoughts here: https://github.com/fondberg/spotcast/issues/241#issuecomment-898217089)
edit: Adding logs with
pychromecast: debug
: