6
6
"""
7
7
from collections import defaultdict
8
8
import logging
9
-
10
- from urllib .error import HTTPError
11
9
import voluptuous as vol
12
10
13
11
from homeassistant .const import (
17
15
from homeassistant .helpers .entity import Entity
18
16
from homeassistant .util import slugify
19
17
20
- REQUIREMENTS = ['teslajsonpy==0.0.17 ' ]
18
+ REQUIREMENTS = ['teslajsonpy==0.0.18 ' ]
21
19
22
20
DOMAIN = 'tesla'
23
21
45
43
46
44
def setup (hass , base_config ):
47
45
"""Set up of Tesla platform."""
48
- from teslajsonpy . controller import Controller as teslaApi
46
+ from teslajsonpy import Controller as teslaAPI , TeslaException
49
47
50
48
config = base_config .get (DOMAIN )
51
49
@@ -55,12 +53,12 @@ def setup(hass, base_config):
55
53
if hass .data .get (DOMAIN ) is None :
56
54
try :
57
55
hass .data [DOMAIN ] = {
58
- 'controller' : teslaApi (
56
+ 'controller' : teslaAPI (
59
57
email , password , update_interval ),
60
58
'devices' : defaultdict (list )
61
59
}
62
60
_LOGGER .debug ("Connected to the Tesla API." )
63
- except HTTPError as ex :
61
+ except TeslaException as ex :
64
62
if ex .code == 401 :
65
63
hass .components .persistent_notification .create (
66
64
"Error:<br />Please check username and password."
@@ -72,12 +70,11 @@ def setup(hass, base_config):
72
70
"Error:<br />Can't communicate with Tesla API.<br />"
73
71
"Error code: {} Reason: {}"
74
72
"You will need to restart Home Assistant after fixing."
75
- "" .format (ex .code , ex .reason ),
73
+ "" .format (ex .code , ex .message ),
76
74
title = NOTIFICATION_TITLE ,
77
75
notification_id = NOTIFICATION_ID )
78
76
_LOGGER .error ("Unable to communicate with Tesla API: %s" ,
79
- ex .reason )
80
-
77
+ ex .message )
81
78
return False
82
79
83
80
all_devices = hass .data [DOMAIN ]['controller' ].list_vehicles ()
0 commit comments