idodov / pixoo64-media-album-art

Displaying the currently playing track’s album cover art on the PIXOO64
14 stars 2 forks source link

AttributeError: 'NoneType' object has no attribute 'startswith' #6

Closed ThreeFN closed 2 weeks ago

ThreeFN commented 2 weeks ago

Unfortunately I've discovered a new bug.

Music playback is on Apple Homepod Mini via airplay from a phone. Seems like AAC may be related to the issue?

2024-10-28 21:30:49.270149 INFO AppDaemon: Calling initialize() for pixoo64_media_album_art
2024-10-28 21:30:49.272205 INFO AppDaemon: App initialization complete
2024-10-28 21:37:21.277804 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:37:21.277971 WARNING pixoo64_media_album_art: Unexpected error in worker for App pixoo64_media_album_art:
2024-10-28 21:37:21.278098 WARNING pixoo64_media_album_art: Worker Ags: {'id': '56e1d829fd33437485d5c9543bc3d401', 'name': 'pixoo64_media_album_art', 'objectid': 'ca2c6d65e0ae49ad81cd61ab714ac8b4', 'type': 'state', 'function': <bound method Pixoo64_Media_Album_Art.update_attributes of <pixoo64_media_album_art.Pixoo64_Media_Album_Art object at 0x7f8f3f10c2d0>>, 'attribute': 'media_title', 'entity': 'media_player.kitchen', 'new_state': 'Thunder & Lightning', 'old_state': 'Do Math With U', 'pin_app': True, 'pin_thread': 1, 'kwargs': {'attribute': 'media_title', '__thread_id': 'thread-1'}}
2024-10-28 21:37:21.278224 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:37:21.279289 WARNING pixoo64_media_album_art: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1045, in worker
    funcref(
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 163, in update_attributes
    self.pixoo_run(media_state)
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 205, in pixoo_run
    if media_content_id.startswith("x-rincon") or media_content_id.startswith("aac:"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'

2024-10-28 21:37:21.279416 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:40:14.915479 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:40:14.915674 WARNING pixoo64_media_album_art: Unexpected error in worker for App pixoo64_media_album_art:
2024-10-28 21:40:14.915802 WARNING pixoo64_media_album_art: Worker Ags: {'id': '56e1d829fd33437485d5c9543bc3d401', 'name': 'pixoo64_media_album_art', 'objectid': 'ca2c6d65e0ae49ad81cd61ab714ac8b4', 'type': 'state', 'function': <bound method Pixoo64_Media_Album_Art.update_attributes of <pixoo64_media_album_art.Pixoo64_Media_Album_Art object at 0x7f8f3f10c2d0>>, 'attribute': 'media_title', 'entity': 'media_player.kitchen', 'new_state': 'Take On Me', 'old_state': 'Thunder & Lightning', 'pin_app': True, 'pin_thread': 1, 'kwargs': {'attribute': 'media_title', '__thread_id': 'thread-1'}}
2024-10-28 21:40:14.915927 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:40:14.916475 WARNING pixoo64_media_album_art: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1045, in worker
    funcref(
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 163, in update_attributes
    self.pixoo_run(media_state)
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 205, in pixoo_run
    if media_content_id.startswith("x-rincon") or media_content_id.startswith("aac:"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'

2024-10-28 21:40:14.916591 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:43:56.542234 INFO AppDaemon: Reading config
2024-10-28 21:43:56.548215 INFO AppDaemon: /homeassistant/appdaemon/apps/apps.yaml added or modified
2024-10-28 21:43:56.548703 INFO AppDaemon: App 'pixoo64_media_album_art' changed
2024-10-28 21:43:56.549182 INFO AppDaemon: Found 2 active apps
2024-10-28 21:43:56.549279 INFO AppDaemon: Found 0 inactive apps
2024-10-28 21:43:56.549357 INFO AppDaemon: Found 0 global libraries
2024-10-28 21:43:56.550655 INFO AppDaemon: Terminating pixoo64_media_album_art
2024-10-28 21:43:56.551402 INFO AppDaemon: Reloading Module: /homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py
2024-10-28 21:43:56.559637 INFO AppDaemon: Loading app pixoo64_media_album_art using class Pixoo64_Media_Album_Art from module pixoo64_media_album_art
2024-10-28 21:43:56.560545 INFO AppDaemon: Calling initialize() for pixoo64_media_album_art
2024-10-28 21:44:13.212105 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:44:13.212245 WARNING pixoo64_media_album_art: Unexpected error in worker for App pixoo64_media_album_art:
2024-10-28 21:44:13.212334 WARNING pixoo64_media_album_art: Worker Ags: {'id': '1df97c8fd7ef4425a3c8bdeac625577d', 'name': 'pixoo64_media_album_art', 'objectid': '65a75aee32da4013a3acdb5dcd0fb945', 'type': 'state', 'function': <bound method Pixoo64_Media_Album_Art.update_attributes of <pixoo64_media_album_art.Pixoo64_Media_Album_Art object at 0x7f8f3e3b8f90>>, 'attribute': 'media_title', 'entity': 'media_player.kitchen', 'new_state': 'The Last Unicorn', 'old_state': 'Take On Me', 'pin_app': True, 'pin_thread': 1, 'kwargs': {'attribute': 'media_title', '__thread_id': 'thread-1'}}
2024-10-28 21:44:13.212474 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:44:13.213019 WARNING pixoo64_media_album_art: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1045, in worker
    funcref(
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 163, in update_attributes
    self.pixoo_run(media_state)
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 205, in pixoo_run
    if media_content_id.startswith("x-rincon") or media_content_id.startswith("aac:"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'

2024-10-28 21:44:13.213143 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:47:01.316350 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:47:01.316544 WARNING pixoo64_media_album_art: Unexpected error in worker for App pixoo64_media_album_art:
2024-10-28 21:47:01.316647 WARNING pixoo64_media_album_art: Worker Ags: {'id': '1df97c8fd7ef4425a3c8bdeac625577d', 'name': 'pixoo64_media_album_art', 'objectid': '65a75aee32da4013a3acdb5dcd0fb945', 'type': 'state', 'function': <bound method Pixoo64_Media_Album_Art.update_attributes of <pixoo64_media_album_art.Pixoo64_Media_Album_Art object at 0x7f8f3e3b8f90>>, 'attribute': 'media_title', 'entity': 'media_player.kitchen', 'new_state': 'More Than a Feeling', 'old_state': 'The Last Unicorn', 'pin_app': True, 'pin_thread': 1, 'kwargs': {'attribute': 'media_title', '__thread_id': 'thread-1'}}
2024-10-28 21:47:01.316733 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:47:01.317176 WARNING pixoo64_media_album_art: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1045, in worker
    funcref(
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 163, in update_attributes
    self.pixoo_run(media_state)
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 205, in pixoo_run
    if media_content_id.startswith("x-rincon") or media_content_id.startswith("aac:"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'

2024-10-28 21:47:01.317274 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:47:37.160212 INFO AppDaemon: Terminating pixoo64_media_album_art
2024-10-28 21:47:37.161310 INFO AppDaemon: Reloading Module: /homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py
2024-10-28 21:47:37.167986 INFO AppDaemon: Loading app pixoo64_media_album_art using class Pixoo64_Media_Album_Art from module pixoo64_media_album_art
2024-10-28 21:47:37.169111 INFO AppDaemon: Calling initialize() for pixoo64_media_album_art
2024-10-28 21:47:55.566981 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:47:55.567125 WARNING pixoo64_media_album_art: Unexpected error in worker for App pixoo64_media_album_art:
2024-10-28 21:47:55.567248 WARNING pixoo64_media_album_art: Worker Ags: {'id': '5e1cdc2886864a28b607bbbd27741252', 'name': 'pixoo64_media_album_art', 'objectid': '8d81758badbd44b9b896e934dfecb2ce', 'type': 'state', 'function': <bound method Pixoo64_Media_Album_Art.update_attributes of <pixoo64_media_album_art.Pixoo64_Media_Album_Art object at 0x7f8f3e48cc10>>, 'attribute': 'media_title', 'entity': 'media_player.kitchen', 'new_state': 'You Can Do Us!', 'old_state': 'More Than a Feeling', 'pin_app': True, 'pin_thread': 1, 'kwargs': {'attribute': 'media_title', '__thread_id': 'thread-1'}}
2024-10-28 21:47:55.567347 WARNING pixoo64_media_album_art: ------------------------------------------------------------
2024-10-28 21:47:55.568006 WARNING pixoo64_media_album_art: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1045, in worker
    funcref(
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 163, in update_attributes
    self.pixoo_run(media_state)
  File "/homeassistant/appdaemon/apps/pixoo64-media-album-art/pixoo64_media_album_art.py", line 205, in pixoo_run
    if media_content_id.startswith("x-rincon") or media_content_id.startswith("aac:"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'

2024-10-28 21:47:55.568110 WARNING pixoo64_media_album_art: ------------------------------------------------------------
idodov commented 2 weeks ago

@ThreeFN, I've updated the script. Please copy the new code from here and paste it into pixoo64_media_album_art.py. This way, you won't need to wait for the HA update checker.

I hope this helps! If the fix resolves the issue, it might also address some related concerns.

A few questions:

Does the script work without using the AirPlay function?

Can you try playing radio stations (from TuneIn)?

From the developer tools, send me the media player attributes while using AirPlay (to see how HA fetches the data and improve if needed).

Looking forward to hearing from you.

ThreeFN commented 2 weeks ago

That did end up working for me, thank you kindly! Sorry that I've been the bearer of bad news as of late.

I'll try to answer your questions regardless in case there is diagnostic info in the answers.

  1. So far, I've only used the script with airplay, since the homepod is an airplay centric device.
  2. you may have to elaborate further on how I would go about using TuneIn diagnostically for you, since I currently am not familiar with TuneIn. For example would I be using TuneIn via app on iphone, which I assume would airplay to the homepod? Or is there a Home Assistant integration for TuneIn? I'm unaware of such an integration.
  3. Before the latest .py update, the media data entity wouldn't get populated, it seemed things would 'crash' before getting to that state. Since the update, here is an snippet (enjoy my taste in music):
sensor.pixoo64_media_data

artist: Ninja Sex Party
normalized_artist: Ninja Sex Party
media_title: I Just Want To (Dance)
normalized_title: I Just Want To (Dance)
font_color: #0000ff
font_color_alternative: #f10000
background_color_brightness: 85
background_color: #ff0000
color_alternative_rgb: #ff0000
background_color_rgb: 255, 0, 0
recommended_font_color_rgb: 241, 0, 0
color_alternative: 255, 0, 0

Also, if you have recommendations on how to make the media data entity 'permanent' that would be helpful, if to at least remove any 'entity doesn't exist' errors. Maybe a template sensor in the HA configuration.yaml and the script would then update 'over' it?

idodov commented 2 weeks ago

Happy to hear things are now working.

The "entity doesn't exist" message is not an error. AppDaemon can only create temporary sensors by default. To avoid seeing that message in the log, you can create the sensor in configuration.yaml as well.

It would be great if you could send me the media_player attributes while using the AirPlay function. I just need to ensure how Home Assistant fetches the unique AirPlay data.

ThreeFN commented 2 weeks ago

That's what I understood to be the case, I feel like I may have done something like that before but I can't remember specifics. I will investigate further.

Sorry, I misunderstood the entity you were interested in, here is the state date for the homepod device media_player.kitchen:

media_player.kitchen

volume_level: 0.488
media_content_type: music
media_duration: 223
media_position: 0
media_position_updated_at: 2024-10-30T22:42:58.027419+00:00
media_title: I Don't Know What We're Talking About (And I Haven't for a While)
media_artist: Ninja Sex Party
media_album_name: The Prophecy
app_id: com.apple.tvairplayd
app_name: Music
shuffle: true
repeat: off
entity_picture: /api/media_player_proxy/media_player.kitchen?token=8d1ffdf2db3762f3f76e256451bb04033ab796acdea7239c4ca7d12608a87eaa&cache=0CEAF5FF-B43F-408B-B743-9636FA84100B
friendly_name: Kitchen
supported_features: 448439
idodov commented 2 weeks ago

It's strange that the URL of the music file isn’t visible (which I need to check the AAC), but if it’s working now as expected, there’s no need for any changes. Thanks a lot for testing and using the script. Hope it adds a splash of color to your Pixoo64!