Don't directly update config entries (#20877)

* Don't directly update config entries

* Use ConfigEntryNotReady

* Fix tests

* Remove old test

* Lint
This commit is contained in:
Paulus Schoutsen 2019-02-13 20:36:06 -08:00 committed by GitHub
parent 161c368c9d
commit 882f5ed079
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 54 additions and 169 deletions

View file

@ -4,7 +4,7 @@ import async_timeout
from aiohttp import CookieJar
from homeassistant import config_entries
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.const import CONF_HOST
from homeassistant.helpers import aiohttp_client
@ -22,7 +22,6 @@ class UniFiController:
self.available = True
self.api = None
self.progress = None
self._cancel_retry_setup = None
@property
def host(self):
@ -47,20 +46,7 @@ class UniFiController:
await self.api.initialize()
except CannotConnect:
retry_delay = 2 ** (tries + 1)
LOGGER.error("Error connecting to the UniFi controller. Retrying "
"in %d seconds", retry_delay)
async def retry_setup(_now):
"""Retry setup."""
if await self.async_setup(tries + 1):
# This feels hacky, we should find a better way to do this
self.config_entry.state = config_entries.ENTRY_STATE_LOADED
self._cancel_retry_setup = hass.helpers.event.async_call_later(
retry_delay, retry_setup)
return False
raise ConfigEntryNotReady
except Exception: # pylint: disable=broad-except
LOGGER.error(
@ -80,12 +66,6 @@ class UniFiController:
Will cancel any scheduled setup retry and will unload
the config entry.
"""
# If we have a retry scheduled, we were never setup.
if self._cancel_retry_setup is not None:
self._cancel_retry_setup()
self._cancel_retry_setup = None
return True
# If the authentication was wrong.
if self.api is None:
return True