Retry tuya setup on auth rate limiting (#44001)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Alex Szlavik 2020-12-08 05:32:48 -05:00 committed by GitHub
parent 572d4cfbe6
commit fca8841e34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 5 deletions

View file

@ -6,6 +6,7 @@ import logging
from tuyaha import TuyaApi
from tuyaha.tuyaapi import (
TuyaAPIException,
TuyaAPIRateLimitException,
TuyaFrequentlyInvokeException,
TuyaNetException,
TuyaServerException,
@ -137,6 +138,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
) as exc:
raise ConfigEntryNotReady() from exc
except TuyaAPIRateLimitException as exc:
_LOGGER.error("Tuya login rate limited")
raise ConfigEntryNotReady() from exc
except TuyaAPIException as exc:
_LOGGER.error(
"Connection error during integration setup. Error: %s",

View file

@ -2,7 +2,12 @@
import logging
from tuyaha import TuyaApi
from tuyaha.tuyaapi import TuyaAPIException, TuyaNetException, TuyaServerException
from tuyaha.tuyaapi import (
TuyaAPIException,
TuyaAPIRateLimitException,
TuyaNetException,
TuyaServerException,
)
import voluptuous as vol
from homeassistant import config_entries
@ -103,7 +108,7 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
tuya.init(
self._username, self._password, self._country_code, self._platform
)
except (TuyaNetException, TuyaServerException):
except (TuyaAPIRateLimitException, TuyaNetException, TuyaServerException):
return RESULT_CONN_ERROR
except TuyaAPIException:
return RESULT_AUTH_FAILED
@ -249,6 +254,11 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
async def async_step_init(self, user_input=None):
"""Handle options flow."""
if self.config_entry.state != config_entries.ENTRY_STATE_LOADED:
_LOGGER.error("Tuya integration not yet loaded")
return self.async_abort(reason="cannot_connect")
if user_input is not None:
dev_ids = user_input.get(CONF_LIST_DEVICES)
if dev_ids:

View file

@ -2,7 +2,7 @@
"domain": "tuya",
"name": "Tuya",
"documentation": "https://www.home-assistant.io/integrations/tuya",
"requirements": ["tuyaha==0.0.8"],
"requirements": ["tuyaha==0.0.9"],
"codeowners": ["@ollo69"],
"config_flow": true
}

View file

@ -23,6 +23,9 @@
}
},
"options": {
"abort": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
},
"step": {
"init": {
"title": "Configure Tuya Options",

View file

@ -2208,7 +2208,7 @@ tp-connected==0.0.4
transmissionrpc==0.11
# homeassistant.components.tuya
tuyaha==0.0.8
tuyaha==0.0.9
# homeassistant.components.twentemilieu
twentemilieu==0.3.0

View file

@ -1073,7 +1073,7 @@ total_connect_client==0.55
transmissionrpc==0.11
# homeassistant.components.tuya
tuyaha==0.0.8
tuyaha==0.0.9
# homeassistant.components.twentemilieu
twentemilieu==0.3.0