diff --git a/homeassistant/components/tibber/__init__.py b/homeassistant/components/tibber/__init__.py index df56989714f..53c02a1461a 100644 --- a/homeassistant/components/tibber/__init__.py +++ b/homeassistant/components/tibber/__init__.py @@ -10,10 +10,13 @@ from homeassistant.const import CONF_ACCESS_TOKEN, CONF_NAME, EVENT_HOMEASSISTAN from homeassistant.helpers import discovery from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.event import async_call_later from homeassistant.util import dt as dt_util DOMAIN = "tibber" +FIRST_RETRY_TIME = 60 + CONFIG_SCHEMA = vol.Schema( {DOMAIN: vol.Schema({vol.Required(CONF_ACCESS_TOKEN): cv.string})}, extra=vol.ALLOW_EXTRA, @@ -22,7 +25,7 @@ CONFIG_SCHEMA = vol.Schema( _LOGGER = logging.getLogger(__name__) -async def async_setup(hass, config): +async def async_setup(hass, config, retry_delay=FIRST_RETRY_TIME): """Set up the Tibber component.""" conf = config.get(DOMAIN) @@ -40,9 +43,16 @@ async def async_setup(hass, config): try: await tibber_connection.update_info() - except asyncio.TimeoutError as err: - _LOGGER.error("Timeout connecting to Tibber: %s ", err) - return False + except asyncio.TimeoutError: + _LOGGER.warning("Timeout connecting to Tibber. Will retry in %ss", retry_delay) + + async def retry_setup(now): + """Retry setup if a timeout happens on Tibber API.""" + await async_setup(hass, config, retry_delay=min(2 * retry_delay, 900)) + + async_call_later(hass, retry_delay, retry_setup) + + return True except aiohttp.ClientError as err: _LOGGER.error("Error connecting to Tibber: %s ", err) return False diff --git a/homeassistant/components/tibber/manifest.json b/homeassistant/components/tibber/manifest.json index 4186e0781fe..78b358d70ec 100644 --- a/homeassistant/components/tibber/manifest.json +++ b/homeassistant/components/tibber/manifest.json @@ -2,7 +2,7 @@ "domain": "tibber", "name": "Tibber", "documentation": "https://www.home-assistant.io/integrations/tibber", - "requirements": ["pyTibber==0.13.2"], + "requirements": ["pyTibber==0.13.3"], "dependencies": [], "codeowners": ["@danielhiversen"], "quality_scale": "silver" diff --git a/requirements_all.txt b/requirements_all.txt index e111164cdcc..2ace08d081c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1116,7 +1116,7 @@ pyRFXtrx==0.25 # pySwitchmate==0.4.6 # homeassistant.components.tibber -pyTibber==0.13.2 +pyTibber==0.13.3 # homeassistant.components.dlink pyW215==0.6.0