waxlamp / elgato

Control program for El Gato brand keylights
Apache License 2.0
9 stars 0 forks source link

Unavailable Key Light (switched off) leads to Exceptions #15

Closed pklaus closed 3 years ago

pklaus commented 3 years ago

A very nice CLI for leglight, thanks!

Encountered Issue: When a previously discovered key light is switched off (and therefore not available on the WiFi/network), the tool fails with ~70 lines of traceback. This applies to calls for elgato, elgato lights or elgato lights --discover.

Expected behaviour: Tool exits without errors (return value 0), but lists all lights that are currently not available separately. In the case of the elgato lights --discovery I would expect that any lights, which are not available would be removed from ~/.config/elgato/discovered.json.


Traceback when calling elgato:

[...]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/philipp/.pyvenv/py38/bin/elgato", line 5, in <module>
    from elgato.__main__ import main
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/elgato/__main__.py", line 108, in <module>
    discovered = get_discovered_lights()
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/elgato/__main__.py", line 105, in get_discovered_lights
    return Discovered(discovered_file)
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/elgato/__main__.py", line 38, in __init__
    self.lights = [
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/elgato/__main__.py", line 39, in <listcomp>
    leglight.LegLight(light["address"], light["port"]) for light in lights
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/leglight/leglight.py", line 16, in __init__
    res = requests.get("http://{}:{}/elgato/accessory-info".format(address,port))
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/home/philipp/.pyvenv/py38/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.1.133', port=9123): Max retries exceeded with url: /elgato/accessory-info (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ff558c383a0>: Failed to establish a new connection: [Errno 113] No route to host'))

content of ~/.config/elgato/discovered.json:

[{"address": "192.168.1.133", "port": 9123}]
waxlamp commented 3 years ago

Hi, thank you for the kind words and the bug report!

I have run into this myself. Thanks for the comprehensive report, it will be helpful in creating a proper bugfix.

In the meantime, the easiest workaround (which probably you have figured out already) is simply to delete the discovered.json file and run the discovery procedure again. I leave my light plugged in continuously, so this problem occurred for me only after a power outage at my home.

If you need to regularly disconnect your light from power or from your network, I can see how this workaround would quickly become tedious. I will work on a fix for this.

waxlamp commented 3 years ago

@pklaus, could you check out / try #16 and see if it solves your problem?

pklaus commented 3 years ago

I installed the version from that branch using pip install git+https://github.com/waxlamp/elgato.git@fix-discovery#egg=PyElgato. Works perfectly now. Thank you for the fix.

waxlamp commented 3 years ago

You're welcome. Thanks again for the bug report. And just FYI, version 1.1.0 of the package is now published to PyPI.