Add Tibber retry (#32554)

* Add retry setup to Tibber

* tibber lib

* update comment

* update comment

* increase delay for every try

* Update homeassistant/components/tibber/__init__.py

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
pull/32578/head
Daniel Høyer Iversen 2020-03-08 12:20:33 +01:00 committed by GitHub
parent 17215709e1
commit b5118c41a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 6 deletions

View File

@ -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

View File

@ -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"

View File

@ -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