Skip to content

Commit 29fb65b

Browse files
zabuldonpvizeli
authored andcommitted
Fixes home-assistant#10030. Extented Network Exceptions handling. (home-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
1 parent 560a4ef commit 29fb65b

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

homeassistant/components/tesla.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
"""
77
from collections import defaultdict
88
import logging
9-
10-
from urllib.error import HTTPError
119
import voluptuous as vol
1210

1311
from homeassistant.const import (
@@ -17,7 +15,7 @@
1715
from homeassistant.helpers.entity import Entity
1816
from homeassistant.util import slugify
1917

20-
REQUIREMENTS = ['teslajsonpy==0.0.17']
18+
REQUIREMENTS = ['teslajsonpy==0.0.18']
2119

2220
DOMAIN = 'tesla'
2321

@@ -45,7 +43,7 @@
4543

4644
def setup(hass, base_config):
4745
"""Set up of Tesla platform."""
48-
from teslajsonpy.controller import Controller as teslaApi
46+
from teslajsonpy import Controller as teslaAPI, TeslaException
4947

5048
config = base_config.get(DOMAIN)
5149

@@ -55,12 +53,12 @@ def setup(hass, base_config):
5553
if hass.data.get(DOMAIN) is None:
5654
try:
5755
hass.data[DOMAIN] = {
58-
'controller': teslaApi(
56+
'controller': teslaAPI(
5957
email, password, update_interval),
6058
'devices': defaultdict(list)
6159
}
6260
_LOGGER.debug("Connected to the Tesla API.")
63-
except HTTPError as ex:
61+
except TeslaException as ex:
6462
if ex.code == 401:
6563
hass.components.persistent_notification.create(
6664
"Error:<br />Please check username and password."
@@ -72,12 +70,11 @@ def setup(hass, base_config):
7270
"Error:<br />Can't communicate with Tesla API.<br />"
7371
"Error code: {} Reason: {}"
7472
"You will need to restart Home Assistant after fixing."
75-
"".format(ex.code, ex.reason),
73+
"".format(ex.code, ex.message),
7674
title=NOTIFICATION_TITLE,
7775
notification_id=NOTIFICATION_ID)
7876
_LOGGER.error("Unable to communicate with Tesla API: %s",
79-
ex.reason)
80-
77+
ex.message)
8178
return False
8279

8380
all_devices = hass.data[DOMAIN]['controller'].list_vehicles()

requirements_all.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ tellduslive==0.3.4
10241024
temperusb==1.5.3
10251025

10261026
# homeassistant.components.tesla
1027-
teslajsonpy==0.0.17
1027+
teslajsonpy==0.0.18
10281028

10291029
# homeassistant.components.thingspeak
10301030
thingspeak==0.4.1

0 commit comments

Comments
 (0)