Skip to content

Commit

Permalink
Fixes home-assistant#10030. Extented Network Exceptions handling. (ho…
Browse files Browse the repository at this point in the history
…me-assistant#10116)

* Fixes home-assistant#10030. Extented Network Exceptions handling.

* Remove unused import. Replace ex.reason to ex.message to use custom exception instead of HTTPError
  • Loading branch information
zabuldon authored and pvizeli committed Oct 24, 2017
1 parent 560a4ef commit 29fb65b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions homeassistant/components/tesla.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"""
from collections import defaultdict
import logging

from urllib.error import HTTPError
import voluptuous as vol

from homeassistant.const import (
Expand All @@ -17,7 +15,7 @@
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify

REQUIREMENTS = ['teslajsonpy==0.0.17']
REQUIREMENTS = ['teslajsonpy==0.0.18']

DOMAIN = 'tesla'

Expand Down Expand Up @@ -45,7 +43,7 @@

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)

Expand All @@ -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."
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29fb65b

Please sign in to comment.