mirror of
https://github.com/home-assistant/core.git
synced 2025-07-04 03:47:09 +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
|
from collections import defaultdict
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from urllib.error import HTTPError
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -17,7 +15,7 @@ from homeassistant.helpers import config_validation as cv
|
|||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
REQUIREMENTS = ['teslajsonpy==0.0.17']
|
REQUIREMENTS = ['teslajsonpy==0.0.18']
|
||||||
|
|
||||||
DOMAIN = 'tesla'
|
DOMAIN = 'tesla'
|
||||||
|
|
||||||
@ -45,7 +43,7 @@ TESLA_COMPONENTS = [
|
|||||||
|
|
||||||
def setup(hass, base_config):
|
def setup(hass, base_config):
|
||||||
"""Set up of Tesla platform."""
|
"""Set up of Tesla platform."""
|
||||||
from teslajsonpy.controller import Controller as teslaApi
|
from teslajsonpy import Controller as teslaAPI, TeslaException
|
||||||
|
|
||||||
config = base_config.get(DOMAIN)
|
config = base_config.get(DOMAIN)
|
||||||
|
|
||||||
@ -55,12 +53,12 @@ def setup(hass, base_config):
|
|||||||
if hass.data.get(DOMAIN) is None:
|
if hass.data.get(DOMAIN) is None:
|
||||||
try:
|
try:
|
||||||
hass.data[DOMAIN] = {
|
hass.data[DOMAIN] = {
|
||||||
'controller': teslaApi(
|
'controller': teslaAPI(
|
||||||
email, password, update_interval),
|
email, password, update_interval),
|
||||||
'devices': defaultdict(list)
|
'devices': defaultdict(list)
|
||||||
}
|
}
|
||||||
_LOGGER.debug("Connected to the Tesla API.")
|
_LOGGER.debug("Connected to the Tesla API.")
|
||||||
except HTTPError as ex:
|
except TeslaException as ex:
|
||||||
if ex.code == 401:
|
if ex.code == 401:
|
||||||
hass.components.persistent_notification.create(
|
hass.components.persistent_notification.create(
|
||||||
"Error:<br />Please check username and password."
|
"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:<br />Can't communicate with Tesla API.<br />"
|
||||||
"Error code: {} Reason: {}"
|
"Error code: {} Reason: {}"
|
||||||
"You will need to restart Home Assistant after fixing."
|
"You will need to restart Home Assistant after fixing."
|
||||||
"".format(ex.code, ex.reason),
|
"".format(ex.code, ex.message),
|
||||||
title=NOTIFICATION_TITLE,
|
title=NOTIFICATION_TITLE,
|
||||||
notification_id=NOTIFICATION_ID)
|
notification_id=NOTIFICATION_ID)
|
||||||
_LOGGER.error("Unable to communicate with Tesla API: %s",
|
_LOGGER.error("Unable to communicate with Tesla API: %s",
|
||||||
ex.reason)
|
ex.message)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
all_devices = hass.data[DOMAIN]['controller'].list_vehicles()
|
all_devices = hass.data[DOMAIN]['controller'].list_vehicles()
|
||||||
|
@ -1024,7 +1024,7 @@ tellduslive==0.3.4
|
|||||||
temperusb==1.5.3
|
temperusb==1.5.3
|
||||||
|
|
||||||
# homeassistant.components.tesla
|
# homeassistant.components.tesla
|
||||||
teslajsonpy==0.0.17
|
teslajsonpy==0.0.18
|
||||||
|
|
||||||
# homeassistant.components.thingspeak
|
# homeassistant.components.thingspeak
|
||||||
thingspeak==0.4.1
|
thingspeak==0.4.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user