mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 05:35:11 +02:00
Manage different cases of ConnectionError
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from requests.exceptions import ConnectionError as RequestsConnectionError
|
||||||
from tuyaha import TuyaApi
|
from tuyaha import TuyaApi
|
||||||
from urllib3.exceptions import NewConnectionError
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_PLATFORM, CONF_USERNAME
|
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):
|
def setup(hass, config, retry_delay=FIRST_RETRY_TIME):
|
||||||
"""Set up Tuya Component."""
|
"""Set up Tuya Component."""
|
||||||
|
|
||||||
_LOGGER.info("Initializing %s domain.", DOMAIN)
|
_LOGGER.debug("Initializing domain")
|
||||||
|
|
||||||
tuya = TuyaApi()
|
tuya = TuyaApi()
|
||||||
username = config[DOMAIN][CONF_USERNAME]
|
username = config[DOMAIN][CONF_USERNAME]
|
||||||
@@ -69,10 +69,12 @@ def setup(hass, config, retry_delay=FIRST_RETRY_TIME):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
tuya.init(username, password, country_code, platform)
|
tuya.init(username, password, country_code, platform)
|
||||||
except NewConnectionError:
|
except RequestsConnectionError as ex:
|
||||||
|
if "NewConnectionError" not in str(ex):
|
||||||
|
raise ex
|
||||||
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Connection error initializing %s domain. Will retry in %s seconds...",
|
"Connection error initializing domain. Will retry in %s seconds.",
|
||||||
DOMAIN,
|
|
||||||
retry_delay,
|
retry_delay,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user