Merge pull request #18928 from home-assistant/tibber_err_handle

Tibber, Improve logging and error handling
This commit is contained in:
Daniel Høyer Iversen 2018-12-04 06:47:50 +01:00 committed by GitHub
commit 31078b2b3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 12 deletions

View file

@ -35,17 +35,21 @@ async def async_setup_platform(hass, config, async_add_entities,
tibber_connection = hass.data.get(TIBBER_DOMAIN)
try:
dev = []
for home in tibber_connection.get_homes():
dev = []
for home in tibber_connection.get_homes():
try:
await home.update_info()
dev.append(TibberSensorElPrice(home))
if home.has_real_time_consumption:
dev.append(TibberSensorRT(home))
except (asyncio.TimeoutError, aiohttp.ClientError):
raise PlatformNotReady()
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.2']
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

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