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
37 stars 5 forks source link

New saturated color profile issue #14

Closed kaizoor closed 9 months ago

kaizoor commented 9 months ago

The newly available color profile saturated leads the add on to crash.

The log is calling out a division by zero issue:

2024-01-23 17:21:52.099660 WARNING spotify_mood_lights_sync: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1045, in worker
    funcref(
  File "/config/apps/ad-spotify-mood-lights-sync/spotify_mood_lights_sync.py", line 166, in sync_lights_from_search
    self.sync_light(track_uri)
  File "/config/apps/ad-spotify-mood-lights-sync/spotify_mood_lights_sync.py", line 170, in sync_light
    color = self.color_from_uri(track_uri)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/apps/ad-spotify-mood-lights-sync/spotify_mood_lights_sync.py", line 195, in color_from_uri
    color = self.color_for_point((valence, energy))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/apps/ad-spotify-mood-lights-sync/spotify_mood_lights_sync.py", line 222, in color_for_point
    red = inv_dist_weighted_sum(self.color_map_colors[0], weights)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/apps/ad-spotify-mood-lights-sync/spotify_mood_lights_sync.py", line 216, in inv_dist_weighted_sum
    return sum(mul_array(v, w)) / sum(weights)
           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
ZeroDivisionError: division by zero

This is the error what gets reported to the appdeamon log.

This is my config:

spotify_mood_lights_sync:
  module: spotify_mood_lights_sync
  class: SpotifyMoodLightsSync
  client_id: !secret spotify_client_id
  client_secret: !secret spotify_client_secret
  media_player: media_player.streamer
  light: light.tvboard
  color_profile: saturated
  mode: search
  max_retries: 1
  constrain_input_boolean: input_boolean.ligtsync

It is working if I use the color_profile: default.

If you need more information let me know. I want to help solve this issue.

Keep up the great work.

NiklasReiche commented 9 months ago

It seems like you're somehow still running version 1.2, which cannot handle the new profile. Did you update through HACS to v1.3.0? Maybe try hitting the redownload button on the HACS page to get the newest release: grafik

kaizoor commented 9 months ago

I only knew about the new colors from the HACS update.

I redownloaded the add on but the problem still persists. I also did a restart off the appdeamon add on.

I looked at the local file to make sure it is using the same file/version as provided here and compared my local and the remote file from github with vimdiff.

NiklasReiche commented 9 months ago

That's weird. In the log message you posted, it says that the error ocurred in line 216, but that corresponds to the prevous release. In the new version that line is something completely different. Looking at the old version's code, your error is also replicable, since the saturated profile is unknown and thus no sample points are initialiazed, leading to a sum of zero in the denominator.

If your installed file is equal to the master branch's, it seems like your Appdaemon or Home Assistant has maybe cached the previous release somehow? Could you try completely restarting Home Assistant if you haven't already?

kaizoor commented 9 months ago

I did some more digging and found the reason.

Your plugin is fine. It is an issue related to the new file structure of appdeamon. HACS is not able to support it. And therefore the file I looked at was up to date but not the file in the actual folder.

I cleared HA manual of all files from this project and did a new installation and the files were put in /homeassistant/appdeamon/apps folder. With the files in this place it would not be know to appdeamon at all. After putting it in the right place in my case /addon_configs/a0d7b954_appdaemon/apps/ad-spotify-mood-lights-sync/spotify_mood_lights_sync.py it worked fine immediately.

To the stat of HACS and the new file structure I found the following: https://github.com/hacs/integration/issues/3408

I am sorry for taking your time even it was not an issue from your side.

Thanks for the help

NiklasReiche commented 9 months ago

I am sorry for taking your time even it was not an issue from your side

No worries.

But this appdaemon add-on situation looks messy. I hadn't noticed since I run appdaemon from the docker container, so thanks for bringing this to my attention. I'll probably add a disclaimer to the readme for now, and look around how other apps handle this.

NiklasReiche commented 9 months ago

For reference, https://github.com/joBr99/nspanel-lovelace-ui/issues/1029#issue-1995332526 describes a workaround for making HACS work with the new AppDaemon add-on.

kaizoor commented 9 months ago

Thanks for letting me know.

I reconfigured my appdeamon and downloads are working nicely now.