TECH7Fox / asterisk-hass-integration

Asterisk integration for Home Assistant
60 stars 14 forks source link

Reconnect AMI #53

Closed TECH7Fox closed 2 years ago

TECH7Fox commented 2 years ago

I'm trying to reconnect the AMI, but I get this error when connecting again:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.9/site-packages/asterisk/manager.py", line 456, in event_dispatch
    if callback(ev, self):
  File "/config/custom_components/asterisk/__init__.py", line 133, in <lambda>
    manager.register_event("Shutdown", lambda event, manager=manager, hass=hass, entry=entry: handle_shutdown(event, manager, hass, entry))
  File "/config/custom_components/asterisk/__init__.py", line 58, in handle_shutdown
    manager.connect(host, port)
  File "/usr/local/lib/python3.9/site-packages/asterisk/manager.py", line 487, in connect
    self.message_thread.start()
  File "/usr/local/lib/python3.9/threading.py", line 887, in start
    raise RuntimeError("threads can only be started once")
RuntimeError: threads can only be started once

Threads can only be started once. Tried using manager.close but that doesn't seem to work. Anyone knows why? Here is the code.

I guess I could redefine manager, but I think that would get rid of all the event listeners from init and the entities.

TECH7Fox commented 2 years ago

Will get fixed by #57