avanc / photOS

Operating System for digital photo frames
Other
96 stars 15 forks source link

[Home Automation] Too many redirects error when HTTP request is made #121

Open lanzer opened 6 months ago

lanzer commented 6 months ago

The suggested home automation HTTP request with Node Red worked perfectly. However, every call ended up causing a "too many redirect" error and causing unnecessary bandwidth across network.

This issue is caused by the web interface issuing a redirect to refresh the admin panel so that it will reflect the new display state. However, if the display state have not changed (ie an action = off was sent but phoOS display is already set to off) , the web interface should not issue a redirect as nothing need to be refreshed. This will prevent the redirect error.

Tried scanning the code base on where this is implemented but no luck, sorry. :)

avanc commented 6 months ago

Thanks for the detailed analysis. I'll keep this and close #118 as duplicate.

lanzer commented 6 months ago

Sorry I had no idea where this file is in the code base but here's the simple fix:

/usr/lib/python3.8/site-packages/webui/plugins/display/display.py

line 31:

        if (self.get_body_argument("action")=="off"):
          if not isOn():
            return True
          setOn(False)
        elif (self.get_body_argument("action")=="on"):
          if isOn():
            return True
          setOn(True)

You already built the isOn function so it's super easy to leverage it and abort the redirect. :)

lanzer commented 6 months ago

Whoops I had "return true" instead "return True", it's been a while since I worked on Python. :)