ericmatte / ad-media-lights-sync

💡 AppDaemon App that synchronize RGB lights with the thumbnail of a media player in Home Assistant. Be sure to ⭐️ my repo!
MIT License
95 stars 9 forks source link

Error when receiving new picture: Fast Octree and libimagequant are the only valid methods for quantizing RGBA images #38

Closed ericmatte closed 3 years ago

ericmatte commented 3 years ago

Issue found by @jaseonline here https://github.com/ericmatte/ad-media-lights-sync/issues/35#issuecomment-783678901

Describe the bug

When loading from a Fire TV, the error is thrown. I do not have any other apps running via AppDaemon and is starts without error:

2021-02-22 21:08:51.725851 INFO AppDaemon: App 'media_lights_sync' added
2021-02-22 21:08:51.728707 INFO AppDaemon: Found 1 total apps
2021-02-22 21:08:51.730313 INFO AppDaemon: Starting Apps with 1 workers and 1 pins
2021-02-22 21:08:51.732747 INFO AppDaemon: Running on port 5050
2021-02-22 21:08:51.804776 INFO HASS: Evaluating startup conditions
2021-02-22 21:08:51.830006 INFO HASS: Startup condition met: hass state=RUNNING
2021-02-22 21:08:51.831183 INFO HASS: All startup conditions met
2021-02-22 21:08:51.878401 INFO AppDaemon: Got initial state from namespace default
2021-02-22 21:08:53.756757 INFO AppDaemon: Scheduler running in realtime
2021-02-22 21:08:53.797530 INFO AppDaemon: Adding /config/appdaemon/apps to module import path
2021-02-22 21:08:53.798942 INFO AppDaemon: Adding /config/appdaemon/apps/ad-media-lights-sync to module import path
2021-02-22 21:08:53.803360 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/ad-media-lights-sync/media_lights_sync.py
2021-02-22 21:08:53.862036 INFO AppDaemon: Initializing app media_lights_sync using class MediaLightsSync from module media_lights_sync
2021-02-22 21:08:54.072214 INFO media_lights_sync: Using default (MedianCut) quantization method
2021-02-22 21:08:54.074755 INFO media_lights_sync: Listening for picture changes on 'media_player.fire_tv_living_room'
2021-02-22 21:08:54.083922 INFO AppDaemon: App initialization complete

As soon as I start Fire TV and New picture received from 'media_player.fire_tv_living_room' (entity_picture) is received, the following error message occurs:

2021-02-22 21:09:30.311110 WARNING media_lights_sync: ------------------------------------------------------------
2021-02-22 21:09:30.312142 WARNING media_lights_sync: Unexpected error in worker for App media_lights_sync:
2021-02-22 21:09:30.313061 WARNING media_lights_sync: Worker Ags: {'id': '0bbd3dabb3f3490897699c3c629fa457', 'name': 'media_lights_sync', 'objectid': 'eda18367f1e941829417c751405c73a2', 'type': 'state', 'function': <bound method MediaLightsSync.change_lights_color of <media_lights_sync.MediaLightsSync object at 0x7f7f854b50>>, 'attribute': 'entity_picture', 'entity': 'media_player.fire_tv_living_room', 'new_state': '/api/media_player_proxy/media_player.fire_tv_living_room?token=36acae52cf4967326d22239587fb79432f886c803f5956e217402fa2b186ce65&cache=1614028163.912325', 'old_state': '/api/media_player_proxy/media_player.fire_tv_living_room?token=36acae52cf4967326d22239587fb79432f886c803f5956e217402fa2b186ce65&cache=1614028153.938489', 'pin_app': True, 'pin_thread': 0, 'kwargs': {'attribute': 'entity_picture', '__thread_id': 'thread-0'}}
2021-02-22 21:09:30.313901 WARNING media_lights_sync: ------------------------------------------------------------
2021-02-22 21:09:30.318557 WARNING media_lights_sync: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/threading.py", line 900, in worker
    funcref(
  File "/config/appdaemon/apps/ad-media-lights-sync/media_lights_sync.py", line 56, in change_lights_color
    rgb_colors = self.get_colors(url)
  File "/config/appdaemon/apps/ad-media-lights-sync/media_lights_sync.py", line 115, in get_colors
    palette = im.quantize(colors=len(self.lights), method=self.quantization_method).getpalette()
  File "/usr/lib/python3.8/site-packages/PIL/Image.py", line 1081, in quantize
    raise ValueError(
ValueError: Fast Octree (method == 2) and libimagequant (method == 3) are the only valid methods for quantizing RGBA images

The image can be viewed fine in my web browser via the api URL.

Additional information

From the PIL.Image documentation, it seems to not work when the image mode is RGBA.

Environment versions

ericmatte commented 3 years ago

@jaseonline could you share me here an example of picture that trigger this error so I could reproduce it?

jaseonline commented 3 years ago

@ericmatte here is my default Fire TV Home screen downloaded from my web browser.

fire-tv-home

ericmatte commented 3 years ago

@jaseonline could you test with this updated code to see if this is properly fixed?: https://github.com/ericmatte/ad-media-lights-sync/blob/ci-tests/apps/media_lights_sync/media_lights_sync.py

Just copy/paste over your existing app in the AppDaemon folder.

ericmatte commented 3 years ago

Should be fixed in v0.7.1.