Better error handling (#11297)

* Better error handling

* Fixed hound
pull/11301/head
Frantz 2017-12-25 18:46:42 +02:00 committed by Pascal Vizeli
parent 802a95eac5
commit 14919082a3
2 changed files with 14 additions and 8 deletions

View File

@ -55,12 +55,15 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
password = config.get(CONF_PASSWORD)
port = config.get(CONF_PORT)
transmission_api = transmissionrpc.Client(
host, port=port, user=username, password=password)
try:
transmission_api = transmissionrpc.Client(
host, port=port, user=username, password=password)
transmission_api.session_stats()
except TransmissionError:
_LOGGER.exception("Connection to Transmission API failed")
except TransmissionError as error:
_LOGGER.error(
"Connection to Transmission API failed on %s:%s with message %s",
host, port, error.original
)
return False
# pylint: disable=global-statement

View File

@ -43,12 +43,15 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
password = config.get(CONF_PASSWORD)
port = config.get(CONF_PORT)
transmission_api = transmissionrpc.Client(
host, port=port, user=username, password=password)
try:
transmission_api = transmissionrpc.Client(
host, port=port, user=username, password=password)
transmission_api.session_stats()
except TransmissionError:
_LOGGING.error("Connection to Transmission API failed")
except TransmissionError as error:
_LOGGING.error(
"Connection to Transmission API failed on %s:%s with message %s",
host, port, error.original
)
return False
add_devices([TransmissionSwitch(transmission_api, name)])