mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
* 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:
parent
560a4ef5eb
commit
29fb65b224
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user