Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't reconnect to AMI #62

Open
TECH7Fox opened this issue Oct 28, 2022 · 0 comments
Open

Can't reconnect to AMI #62

TECH7Fox opened this issue Oct 28, 2022 · 0 comments

Comments

@TECH7Fox
Copy link

Hi, I'm trying to reconnect on a shutdown event. But when Asterisk is back and it does reconnect, it fails with a RuntimeError: threads can only be started once.

Here is my shutdown event:

def handle_shutdown(event, manager, hass, entry):
    _LOGGER.error("Asterisk shutting down.")

    manager.close()

    host = entry.data[CONF_HOST]
    port = entry.data[CONF_PORT]
    username = entry.data[CONF_USERNAME]
    password = entry.data[CONF_PASSWORD]

    while True:
        sleep(30)
        try:
            manager.connect(host, port)
            manager.login(username, password)
            _LOGGER.info("Succesfully reconnected.")
            break
        except asterisk.manager.ManagerException as exception:
            _LOGGER.error("Error reconnecting to Asterisk: %s", exception.args[1])

Would be great to get this to work for a Asterisk integration for Home Assistant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant