anotherjulien / OWNd

OpenWebNet daemon
GNU Lesser General Public License v3.0
30 stars 11 forks source link

Improve usability #5

Open f18m opened 8 months ago

f18m commented 8 months ago

Improve logging (e.g. clearly state when connection is successful) Fix crash when using OWNd module and issuing a CTRL+C Improve README

f18m commented 8 months ago

hi @anotherjulien , first of all thanks for this very well-written library!

In this PR I fixed a dummy issue happening when the OWNd main.py module is stuck in the discovery step and then you hit CTRL+C. I was getting this stackstrace:

$ python3 -m OWNd --address 192.168.1.6 --password willy111 --verbose 2
/home/fmontorsi/Documents/OWNd/OWNd/__main__.py:126: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
2024-02-07 00:02:26,815 - OWNd - INFO - Starting OWNd.
^C   # CTRL+C hit
2024-02-07 00:02:34,869 - OWNd - INFO - Stoping OWNd.
2024-02-07 00:02:34,870 - OWNd - INFO - OWNd stopped.
Traceback (most recent call last):
  File "/home/fmontorsi/Documents/OWNd/OWNd/__main__.py", line 132, in <module>
    loop.run_forever()
  File "/usr/lib64/python3.12/asyncio/base_events.py", line 638, in run_forever
    self._run_once()
  File "/usr/lib64/python3.12/asyncio/base_events.py", line 1933, in _run_once
    event_list = self._selector.select(timeout)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/selectors.py", line 468, in select
    fd_event_list = self._selector.poll(timeout, max_ev)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/fmontorsi/Documents/OWNd/OWNd/__main__.py", line 137, in <module>
    loop.run_until_complete(event_session.close())
  File "/usr/lib64/python3.12/asyncio/base_events.py", line 684, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/fmontorsi/Documents/OWNd/OWNd/connection.py", line 313, in close
    self._stream_writer.close()
    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'OWNEventSession' object has no attribute '_stream_writer'

The reason was that OWNEventSession was an empty object with no declared _stream_writer. I added initialization to None just after the annotation in the ctor. Then I had to add some guard against _stream_writer or _gateway being None.

f18m commented 6 months ago

@anotherjulien ping on this PR... thanks