diyhue / diyHue

Main diyHue software repo
https://diyhue.org/
Other
1.52k stars 274 forks source link

"IndexError: list index out of range" when Entertainment Mode with LCX004 and LCX006 Gradient Strips and X, Y and Z are set to 0 (as they are set in Automatic Entertainment Areas - iLightshow for exemple) #967

Closed igorcv88 closed 7 months ago

igorcv88 commented 7 months ago

Issue does not already exist?

I have searched and found no existing issue

Select Environment

Install Script

Home Assistant related?

No

Description

Entertainment kept crashing and stopping every time I started iLightshow ever since I flashed my WS2812B Strip with the Hue_Gradient_Lightstrip_WS2812 Sketch (as it was no longer LCX002 (TV), and became LCX004 (Independent Gradient Strip)). The error bellow is what showed in the log.

Also, because of this error, the Hue App crashed until I went in Hue Essentials and deleted the automatic Entertainment Area created by the iLightshow app.

So I made this change to the init.py HueObjects file (lines 878 - 887):

loops = 1
gradientStrip = False
if light().modelid in ["LCX001", "LCX002", "LCX003"]:
    loops = len(gradienStripPositions)
elif light().modelid in ["915005987201", "LCX004", "LCX006"]:
    loops = 3

for x in range(loops):
    channel = {
        "channel_id": channel_id,
loops = 1
gradientStrip = False
if light().modelid in ["LCX001", "LCX002", "LCX003"]:
    loops = len(gradienStripPositions)
elif light().modelid in ["915005987201", "LCX004", "LCX006"]:
    loops = len(self.locations[light()])

for x in range(loops):
    print("x:", x)
    channel = {
        "channel_id": channel_id,

This solved all the issues in Entertainment with Gradient Strips and helped to debug, as well as fixed the instability with the Hue App.

Errorlog:

Dec 04 04:33:54 raspberrypi python[133124]: IndexError: list index out of range
Dec 04 04:33:54 raspberrypi python[133124]:     channel["position"] = {"x": (self.locations[light()][0]["x"] + self.locations[light()][1]["x"]) / 2, "y": (self.locations[light(
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/diyHue/BridgeEmulator/HueObjects/__init__.py", line 909, in getV2Api
Dec 04 04:33:54 raspberrypi python[133124]:     "data": [self.getV2Api()],
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/diyHue/BridgeEmulator/HueObjects/__init__.py", line 765, in update_attr
Dec 04 04:33:54 raspberrypi python[133124]:     bridgeConfig[resource][resourceid].update_attr(putDict)
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/diyHue/BridgeEmulator/flaskUI/restful.py", line 364, in put
Dec 04 04:33:54 raspberrypi python[133124]:     resp = meth(*args, **kwargs)
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/.pyenv/versions/3.9.18/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
Dec 04 04:33:54 raspberrypi python[133124]:     return current_app.ensure_sync(self.dispatch_request)(*args, **kwargs)
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/.pyenv/versions/3.9.18/lib/python3.9/site-packages/flask/views.py", line 84, in view
Dec 04 04:33:54 raspberrypi python[133124]:     resp = resource(*args, **kwargs)
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/.pyenv/versions/3.9.18/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
Dec 04 04:33:54 raspberrypi python[133124]:     return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/.pyenv/versions/3.9.18/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
Dec 04 04:33:54 raspberrypi python[133124]:     rv = self.dispatch_request()
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/.pyenv/versions/3.9.18/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
Dec 04 04:33:54 raspberrypi python[133124]: Traceback (most recent call last):
Dec 04 04:33:54 raspberrypi python[133124]: [2023-12-04 01:33:54,574] ERROR in app: Exception on /api/bb1bc15c925b11ee9b81d83add210e04/groups/5 [PUT]
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/.pyenv/versions/3.9.18/lib/python3.9/threading.py", line 917, in run
Dec 04 04:33:54 raspberrypi python[133124]:     self.run()
Dec 04 04:33:54 raspberrypi python[133124]:   File "/home/igorvieira/.pyenv/versions/3.9.18/lib/python3.9/threading.py", line 980, in _bootstrap_inner
Dec 04 04:33:54 raspberrypi python[133124]: Traceback (most recent call last):
Dec 04 04:33:54 raspberrypi python[133124]: Exception in thread Thread-215:

Steps to reproduce

Already stated.

Please enter your operating system details here

Raspberry Pi 4B 4GB with a 256GB SSD (Local Machine)

MacBook Air M1 8GB with 256GB SSD and MacOS 14.0 Beta (Remote Machine)

What DiyHue version(branch) are you using?

master (latest)

igorcv88 commented 7 months ago

Also to note, after this change, Entertainment is running super smooth with NO LAG and with great responsiveness.

mariusmotea commented 7 months ago

Hi, i can push your changes, but if you want to have a recorded contribution to the project you can create a pull request and i will merge it right away.

igorcv88 commented 7 months ago

Will do right away