Fixes #10030. Extented Network Exceptions handling. (#10116)

* Fixes #10030. Extented Network Exceptions handling.

* Remove unused import. Replace ex.reason to ex.message to use custom exception instead of HTTPError
This commit is contained in:
Sergey Isachenko 2017-10-24 20:15:25 +03:00 committed by Pascal Vizeli
parent 560a4ef5eb
commit 29fb65b224
2 changed files with 7 additions and 10 deletions

View File

@ -6,8 +6,6 @@ https://home-assistant.io/components/tesla/
"""
from collections import defaultdict
import logging
from urllib.error import HTTPError
import voluptuous as vol
from homeassistant.const import (
@ -17,7 +15,7 @@ from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify
REQUIREMENTS = ['teslajsonpy==0.0.17']
REQUIREMENTS = ['teslajsonpy==0.0.18']
DOMAIN = 'tesla'
@ -45,7 +43,7 @@ TESLA_COMPONENTS = [
def setup(hass, base_config):
"""Set up of Tesla platform."""
from teslajsonpy.controller import Controller as teslaApi
from teslajsonpy import Controller as teslaAPI, TeslaException
config = base_config.get(DOMAIN)
@ -55,12 +53,12 @@ def setup(hass, base_config):
if hass.data.get(DOMAIN) is None:
try:
hass.data[DOMAIN] = {
'controller': teslaApi(
'controller': teslaAPI(
email, password, update_interval),
'devices': defaultdict(list)
}
_LOGGER.debug("Connected to the Tesla API.")
except HTTPError as ex:
except TeslaException as ex:
if ex.code == 401:
hass.components.persistent_notification.create(
"Error:<br />Please check username and password."
@ -72,12 +70,11 @@ def setup(hass, base_config):
"Error:<br />Can't communicate with Tesla API.<br />"
"Error code: {} Reason: {}"
"You will need to restart Home Assistant after fixing."
"".format(ex.code, ex.reason),
"".format(ex.code, ex.message),
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)
_LOGGER.error("Unable to communicate with Tesla API: %s",
ex.reason)
ex.message)
return False
all_devices = hass.data[DOMAIN]['controller'].list_vehicles()

View File

@ -1024,7 +1024,7 @@ tellduslive==0.3.4
temperusb==1.5.3
# homeassistant.components.tesla
teslajsonpy==0.0.17
teslajsonpy==0.0.18
# homeassistant.components.thingspeak
thingspeak==0.4.1