From b70f7b4d9cb55be7554161a7e8fc284876a20db1 Mon Sep 17 00:00:00 2001 From: ollo69 <60491700+ollo69@users.noreply.github.com> Date: Sun, 12 Apr 2020 15:27:43 +0200 Subject: [PATCH] Manage different cases of ConnectionError --- homeassistant/components/tuya/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/tuya/__init__.py b/homeassistant/components/tuya/__init__.py index 137cea7b25a..1022576a24b 100644 --- a/homeassistant/components/tuya/__init__.py +++ b/homeassistant/components/tuya/__init__.py @@ -2,8 +2,8 @@ from datetime import timedelta import logging +from requests.exceptions import ConnectionError as RequestsConnectionError from tuyaha import TuyaApi -from urllib3.exceptions import NewConnectionError import voluptuous as vol from homeassistant.const import CONF_PASSWORD, CONF_PLATFORM, CONF_USERNAME @@ -59,7 +59,7 @@ CONFIG_SCHEMA = vol.Schema( def setup(hass, config, retry_delay=FIRST_RETRY_TIME): """Set up Tuya Component.""" - _LOGGER.info("Initializing %s domain.", DOMAIN) + _LOGGER.debug("Initializing domain") tuya = TuyaApi() username = config[DOMAIN][CONF_USERNAME] @@ -69,10 +69,12 @@ def setup(hass, config, retry_delay=FIRST_RETRY_TIME): try: tuya.init(username, password, country_code, platform) - except NewConnectionError: + except RequestsConnectionError as ex: + if "NewConnectionError" not in str(ex): + raise ex + _LOGGER.warning( - "Connection error initializing %s domain. Will retry in %s seconds...", - DOMAIN, + "Connection error initializing domain. Will retry in %s seconds.", retry_delay, )