Enable sisyphus to recover from bad DNS without restart (#32846)

pull/33814/head
Jonathan Keljo 2020-04-02 07:33:54 -07:00 committed by Paulus Schoutsen
parent e86fb3fc5c
commit ef5f4b2aca
1 changed files with 11 additions and 6 deletions

View File

@ -99,18 +99,23 @@ class TableHolder:
async def get_table(self):
"""Return the Table held by this holder, connecting to it if needed."""
if self._table:
return self._table
if not self._table_task:
self._table_task = self._hass.async_create_task(self._connect_table())
return await self._table_task
async def _connect_table(self):
self._table = await Table.connect(self._host, self._session)
if self._name is None:
self._name = self._table.name
_LOGGER.debug("Connected to %s at %s", self._name, self._host)
return self._table
try:
self._table = await Table.connect(self._host, self._session)
if self._name is None:
self._name = self._table.name
_LOGGER.debug("Connected to %s at %s", self._name, self._host)
return self._table
finally:
self._table_task = None
async def close(self):
"""Close the table held by this holder, if any."""