Improve err handling

This commit is contained in:
Daniel Høyer Iversen 2018-12-03 20:53:18 +01:00
parent fb12294bb7
commit df3c683023
3 changed files with 15 additions and 6 deletions

View File

@ -12,6 +12,7 @@ from datetime import timedelta
import aiohttp
from homeassistant.components.tibber import DOMAIN as TIBBER_DOMAIN
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.entity import Entity
from homeassistant.util import dt as dt_util
from homeassistant.util import Throttle
@ -38,13 +39,17 @@ async def async_setup_platform(hass, config, async_add_entities,
for home in tibber_connection.get_homes():
try:
await home.update_info()
except (asyncio.TimeoutError, aiohttp.ClientError):
pass
except asyncio.TimeoutError as err:
_LOGGER.error("Timeout connecting to Tibber home: %s ", err)
raise PlatformNotReady()
except aiohttp.ClientError as err:
_LOGGER.error("Error connecting to Tibber home: %s ", err)
raise PlatformNotReady()
dev.append(TibberSensorElPrice(home))
if home.has_real_time_consumption:
dev.append(TibberSensorRT(home))
async_add_entities(dev, True)
async_add_entities(dev, False)
class TibberSensorElPrice(Entity):

View File

@ -16,7 +16,7 @@ from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, CONF_ACCESS_TOKEN,
from homeassistant.helpers import discovery
from homeassistant.helpers.aiohttp_client import async_get_clientsession
REQUIREMENTS = ['pyTibber==0.8.3']
REQUIREMENTS = ['pyTibber==0.8.4']
DOMAIN = 'tibber'
@ -45,7 +45,11 @@ async def async_setup(hass, config):
try:
await tibber_connection.update_info()
except (asyncio.TimeoutError, aiohttp.ClientError):
except asyncio.TimeoutError as err:
_LOGGER.error("Timeout connecting to Tibber: %s ", err)
return False
except aiohttp.ClientError as err:
_LOGGER.error("Error connecting to Tibber: %s ", err)
return False
except tibber.InvalidLogin as exp:
_LOGGER.error("Failed to login. %s", exp)

View File

@ -827,7 +827,7 @@ pyRFXtrx==0.23
pySwitchmate==0.4.4
# homeassistant.components.tibber
pyTibber==0.8.3
pyTibber==0.8.4
# homeassistant.components.switch.dlink
pyW215==0.6.0