Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7b9cbcc
Merge pull request #1 from home-assistant/dev
ollo69 Apr 2, 2020
7b1cabb
Merge pull request #2 from home-assistant/dev
ollo69 Apr 3, 2020
3dea427
Merge pull request #3 from home-assistant/dev
ollo69 Apr 4, 2020
f2699b3
Merge pull request #4 from home-assistant/dev
ollo69 Apr 11, 2020
aada505
Tuya initialization retry on failure
ollo69 Apr 11, 2020
eb64087
Rename exception
ollo69 Apr 11, 2020
3c3412f
Changed managed exception
ollo69 Apr 12, 2020
a87a35d
Manage different cases of ConnectionError
ollo69 Apr 12, 2020
7db0923
Log messages correction
ollo69 Apr 12, 2020
c5548b7
Test always catching exceptions
ollo69 Apr 26, 2020
2298b25
Update for Lint
ollo69 Apr 26, 2020
58ee0a2
Update tuya library to 0.0.6
ollo69 Apr 26, 2020
ce86d50
Merge pull request #5 from home-assistant/dev
ollo69 Apr 27, 2020
0ca8f1c
Tuya initialization retry on failure
ollo69 Apr 11, 2020
4c4a741
Rename exception
ollo69 Apr 11, 2020
473e7fe
Changed managed exception
ollo69 Apr 12, 2020
b70f7b4
Manage different cases of ConnectionError
ollo69 Apr 12, 2020
ee1f86a
Log messages correction
ollo69 Apr 12, 2020
66b3c56
Test always catching exceptions
ollo69 Apr 26, 2020
bb3edc1
Update for Lint
ollo69 Apr 26, 2020
0742363
Update tuya library to 0.0.6
ollo69 Apr 26, 2020
7fb797d
Catch wrong credential
ollo69 Apr 27, 2020
92d15c8
Revert "Catch wrong credential"
ollo69 Apr 27, 2020
02c0d44
Merge branch 'tuya-startup-fix' of https://github.com/ollo69/core int…
ollo69 Apr 27, 2020
f0e4862
Catch wrong credential
ollo69 Apr 27, 2020
7aff7f5
Remove trailing whitespace
ollo69 Apr 27, 2020
f24af0e
Black formatting
ollo69 Apr 27, 2020
d3e379a
Import Exception from tuyaapi
ollo69 Apr 27, 2020
6575a71
Remove str to exception
ollo69 Apr 27, 2020
192e6c9
Force CI checks
ollo69 Apr 28, 2020
eb93237
Force CI checks
ollo69 Apr 28, 2020
bd0520a
Merge pull request #6 from home-assistant/dev
ollo69 Apr 29, 2020
2d5bc52
Rebase conflict
ollo69 Apr 29, 2020
8064c73
Tuya initialization retry on failure
ollo69 Apr 11, 2020
b22652a
Rename exception
ollo69 Apr 11, 2020
9affd74
Changed managed exception
ollo69 Apr 12, 2020
34b14b4
Manage different cases of ConnectionError
ollo69 Apr 12, 2020
0059bf9
Log messages correction
ollo69 Apr 12, 2020
7c6e368
Test always catching exceptions
ollo69 Apr 26, 2020
48678be
Update for Lint
ollo69 Apr 26, 2020
7cbb41e
Update tuya library to 0.0.6
ollo69 Apr 26, 2020
d00297a
Catch wrong credential
ollo69 Apr 27, 2020
f33394d
Revert "Catch wrong credential"
ollo69 Apr 27, 2020
aa516a6
Tuya initialization retry on failure
ollo69 Apr 11, 2020
a810e3c
Rename exception
ollo69 Apr 11, 2020
92de8fc
Changed managed exception
ollo69 Apr 12, 2020
71172b3
Catch wrong credential
ollo69 Apr 27, 2020
f0ccc60
Force CI checks
ollo69 Apr 28, 2020
9b62294
Force CI checks
ollo69 Apr 28, 2020
82da99f
Rebase conflict
ollo69 Apr 29, 2020
8303b81
Rebase
ollo69 Apr 29, 2020
4349841
Merge branch 'tuya-startup-fix' of https://github.com/ollo69/core int…
ollo69 Apr 29, 2020
80d9d9e
Force Test
ollo69 Apr 29, 2020
ad600bc
Force Test
ollo69 Apr 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions homeassistant/components/tuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging

from tuyaha import TuyaApi
from tuyaha.tuyaapi import TuyaAPIException, TuyaNetException, TuyaServerException
import voluptuous as vol

from homeassistant.const import CONF_PASSWORD, CONF_PLATFORM, CONF_USERNAME
Expand All @@ -11,7 +12,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import track_time_interval
from homeassistant.helpers.event import call_later, track_time_interval

_LOGGER = logging.getLogger(__name__)

Expand All @@ -22,6 +23,9 @@
DOMAIN = "tuya"
DATA_TUYA = "data_tuya"

FIRST_RETRY_TIME = 60
MAX_RETRY_TIME = 900

SIGNAL_DELETE_ENTITY = "tuya_delete"
SIGNAL_UPDATE_ENTITY = "tuya_update"

Expand Down Expand Up @@ -52,17 +56,41 @@
)


def setup(hass, config):
def setup(hass, config, retry_delay=FIRST_RETRY_TIME):
"""Set up Tuya Component."""

_LOGGER.debug("Setting up integration")

tuya = TuyaApi()
username = config[DOMAIN][CONF_USERNAME]
password = config[DOMAIN][CONF_PASSWORD]
country_code = config[DOMAIN][CONF_COUNTRYCODE]
platform = config[DOMAIN][CONF_PLATFORM]

try:
tuya.init(username, password, country_code, platform)
except (TuyaNetException, TuyaServerException):
Comment thread
MartinHjelmare marked this conversation as resolved.

_LOGGER.warning(
"Connection error during integration setup. Will retry in %s seconds",
retry_delay,
)

def retry_setup(now):
"""Retry setup if a error happens on tuya API."""
setup(hass, config, retry_delay=min(2 * retry_delay, MAX_RETRY_TIME))

call_later(hass, retry_delay, retry_setup)

return True

except TuyaAPIException as exc:
_LOGGER.error(
"Connection error during integration setup. Error: %s", exc,
)
return False

hass.data[DATA_TUYA] = tuya
tuya.init(username, password, country_code, platform)
hass.data[DOMAIN] = {"entities": {}}

def load_devices(device_list):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tuya/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"domain": "tuya",
"name": "Tuya",
"documentation": "https://www.home-assistant.io/integrations/tuya",
"requirements": ["tuyaha==0.0.5"],
"requirements": ["tuyaha==0.0.6"],
"codeowners": []
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ tp-connected==0.0.4
transmissionrpc==0.11

# homeassistant.components.tuya
tuyaha==0.0.5
tuyaha==0.0.6

# homeassistant.components.twentemilieu
twentemilieu==0.3.0
Expand Down