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
671 stars 96 forks source link

Spotcast breaks with HA 2024.10.0b0 #460

Open hmmbob opened 3 days ago

hmmbob commented 3 days ago

Bug Ticket

Describe the bug

Spotcast breaks when you upgrade from HA 2024.9 to 2024.10

Likely a regression because of https://github.com/home-assistant/core/pull/123548

Troubleshooting

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

Environment

Logs

2024-09-26 21:01:41.484 ERROR (MainThread) [homeassistant.components.script.start_music_t] Slaaptijd: Error executing script. Unexpected error for call_service at pos 2: 'SpotifyMediaPlayer' object has no attribute 'data'
Traceback (most recent call last):
File "/config/custom_components/spotcast/helpers.py", line 39, in get_spotify_media_player
entity_devices = entity._devices
^^^^^^^^^^^^^^^
AttributeError: 'SpotifyMediaPlayer' object has no attribute '_devices'. Did you mean: 'devices'?
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
return await long_task
^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2811, in _execute_service
return await self._hass.async_add_executor_job(target, service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/__init__.py", line 256, in start_casting
spotify_device_id = spotcast_controller.get_spotify_device_id(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/spotcast_controller.py", line 284, in get_spotify_device_id
spotify_device_id = self._getSpotifyConnectDeviceId(client, device_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/spotcast_controller.py", line 268, in _getSpotifyConnectDeviceId
media_player = get_spotify_media_player(self.hass, client._get("me")["id"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/helpers.py", line 41, in get_spotify_media_player
entity_devices = entity.data.devices.data
^^^^^^^^^^^
AttributeError: 'SpotifyMediaPlayer' object has no attribute 'data'
2024-09-26 21:01:41.491 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/config/custom_components/spotcast/helpers.py", line 39, in get_spotify_media_player
entity_devices = entity._devices
^^^^^^^^^^^^^^^
AttributeError: 'SpotifyMediaPlayer' object has no attribute '_devices'. Did you mean: 'devices'?
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 707, in _async_run
return await self.script.async_run(script_vars, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1795, in async_run
return await asyncio.shield(create_eager_task(run.async_run()))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 463, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 557, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 763, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 726, in _async_run_long_action
return await long_task
^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2811, in _execute_service
return await self._hass.async_add_executor_job(target, service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/__init__.py", line 256, in start_casting
spotify_device_id = spotcast_controller.get_spotify_device_id(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/spotcast_controller.py", line 284, in get_spotify_device_id
spotify_device_id = self._getSpotifyConnectDeviceId(client, device_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/spotcast_controller.py", line 268, in _getSpotifyConnectDeviceId
media_player = get_spotify_media_player(self.hass, client._get("me")["id"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/helpers.py", line 41, in get_spotify_media_player
entity_devices = entity.data.devices.data
^^^^^^^^^^^
AttributeError: 'SpotifyMediaPlayer' object has no attribute 'data'
FrancoLoco commented 3 days ago

I have the same problem thanks

fcusson commented 2 days ago

Home assistant must have changed the structure of the media player entity.

We could print to debug the Dir of the object

fcusson commented 2 days ago

Seems that they moved SpotifyMediaPlayer.data.devices to SpotifyMediaPlayer.devices. Testing if it resolves the issue

fcusson commented 1 day ago

ok can confirm the issue is with the new coordinator. We used to have access to a device callable that would provide the devices linked to an account, but devices is now a DataUpdateCoordinator. I don't have enough detail yet to understand how to interact with these Coordinator, I'll try to do some digging, but if others can help I wouldn't mind

fcusson commented 1 day ago

ok found the solution, had to add the hass object to the get_spotify_device_id function to force the refresh of the data. Its now working.

This might be a really good improvement, because that would also mean we can force refresh the list of devices now.

fcusson commented 1 day ago

Tested in version 2024.10.0b4 and 2024.9.3. Both working without issues. I'm going to release the preventive fix for the beta

fcusson commented 1 day ago

Closing with release of v3.8.2 Please reopen of bug still appears from your side

Flibbmaster commented 1 day ago

For me, Version 3.8.2 does not work on HA 2024.9.3. I updated today, directly after the restart the playlists and players stay empty in spotcard. Protocol monitors some errors:

Logger: homeassistant Quelle: custom_components/spotcast/init.py:146 Integration: Spotcast (Dokumentation, Probleme) Erstmals aufgetreten: 15:23:32 (1 Vorkommnisse) Zuletzt protokolliert: 15:23:32

Error doing job: Task exception was never retrieved (None) Traceback (most recent call last): File "/config/custom_components/spotcast/helpers.py", line 122, in run return await loop.run_in_executor(executor, pfunc) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/spotcast/init.py", line 146, in get_devices resp = get_spotify_devices(spotify_media_player) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: get_spotify_devices() missing 1 required positional argument: 'hass'

Going back to 3.8.1 and everything works as expected.

hmmbob commented 1 day ago

Works for 2024.10 indeed, thanks.

@fcusson To fix

For me, Version 3.8.2 does not work on HA 2024.9.3. I updated today, directly after the restart the playlists and players stay empty in spotcard. Protocol monitors some errors:

Going back to 3.8.1 and everything works as expected.

You could raise the HA version in hacs.json to 2024.10.0b0:

https://github.com/fondberg/spotcast/blob/cb2f905a6c62022b4a97a0f611026c409e661e3f/hacs.json#L4

User that are on an older version will not get this update pushed by HACS then. I don't think you need a new release for that, just change the json.

fcusson commented 1 day ago

@hmmbob hmmm... I added new validation, we should still hit the old structure first, this is weird. I'll take a look, can you give me a link to the spotcard you are using?

hmmbob commented 1 day ago

Oh, it's working for me!

You need @Flibbmaster support

fcusson commented 1 day ago

@hmmbob

Oh, it's working for me!

Sorry misread that part

@Flibbmaster if you could provide some details, I might have the spotcard you are mentionning in my regression tests

Flibbmaster commented 1 day ago

Hi, @fcusson ,

Using this Lovelace Card from HACS: https://community.home-assistant.io/t/spotify-lovelace-card/103525

fcusson commented 1 day ago

ok thanks, I'll check, but I know it is now breaking a lot. I don't have access to this project from Fondberg, I'll see what I can do, but it might become an abandonware saddly.

Flibbmaster commented 21 hours ago

@fcusson Totally understood, that card is not from you, so no responsibility on your side. For me it was just the easiest way to implement the playlists and players in a single card in the Dashboard.

MDV85 commented 2 hours ago

Same.... Spotify Card not work after update to ver. 3.8.2 ...((( https://github.com/custom-cards/spotify-card