NiklasReiche / ad-spotify-mood-lights-sync

AppDaemon app that synchronizes rgb lights to the mood of the currently playing spotify song in Home Assistant.
MIT License
35 stars 5 forks source link

'NoneType' is not subscriptable #3

Closed DanteFragapane closed 3 years ago

DanteFragapane commented 3 years ago

Hi, I get an error about TypeError: 'NoneType' object is not subscriptable and I'm not quite sure what is going on. I did copy and paste the client id and secrets from the spotify dev portal. I also customized the config provided to use the right light and media players for my setup


2021-03-30 00:31:57.650239 WARNING spotify_mood_lights_sync: ------------------------------------------------------------
2021-03-30 00:31:57.650819 WARNING spotify_mood_lights_sync: Unexpected error in worker for App spotify_mood_lights_sync:
2021-03-30 00:31:57.651440 WARNING spotify_mood_lights_sync: Worker Ags: {'id': '07e9a6293f2d4eed89647e4a13dafc97', 'name': 'spotify_mood_lights_sync', 'objectid': 'e5f233e2909c41e9ba1c08e6c4724732', 'type': 'state', 'function': <bound method SpotifyMoodLightsSync.sync_lights_from_spotify of <spotify_mood_lights_sync.SpotifyMoodLightsSync object at 0x7f9ad15864f0>>, 'attribute': 'media_content_id', 'entity': 'media_player.bedroom', 'new_state': 'x-sonos-spotify:spotify%3atrack%3a20hsdn8oITBsuWNLhzr5eh?sid=12&flags=8224&sn=6', 'old_state': 'x-sonos-spotify:spotify%3atrack%3a1r1fPuhj9H4VdXr7OK6FL5?sid=12&flags=8224&sn=6', 'pin_app': True, 'pin_thread': 1, 'kwargs': {'attribute': 'media_content_id', '__thread_id': 'thread-1'}}
2021-03-30 00:31:57.651952 WARNING spotify_mood_lights_sync: ------------------------------------------------------------
2021-03-30 00:31:57.652743 WARNING spotify_mood_lights_sync: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/threading.py", line 903, in worker
    funcref(
  File "/config/appdaemon/apps/ad-spotify-mood-lights-sync/spotify_mood_lights_sync.py", line 127, in sync_lights_from_spotify
    self.sync_light(new_uri)
  File "/config/appdaemon/apps/ad-spotify-mood-lights-sync/spotify_mood_lights_sync.py", line 163, in sync_light
    color = self.color_from_uri(track_uri)
  File "/config/appdaemon/apps/ad-spotify-mood-lights-sync/spotify_mood_lights_sync.py", line 189, in color_from_uri
    valence: float = track_features['valence']
TypeError: 'NoneType' object is not subscriptable
2021-03-30 00:31:57.653189 WARNING spotify_mood_lights_sync: ------------------------------------------------------------```
DanteFragapane commented 3 years ago

Problem solved! Config item mode must be set to search for non-spotify media players, as stated in the configuration readme. I had wrongly assumed that Sonos would count, and it does not. Works like a charm now!

NiklasReiche commented 3 years ago

Hey, thanks for letting me know of this uncaught exception. I have now added error handling for this case and clarified the different media player types in the readme a bit more.