pyst2
pyst2 copied to clipboard
Can't reconnect to AMI
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.