Retry tuya setup on auth rate limiting (#44001)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
572d4cfbe6
commit
fca8841e34
6 changed files with 23 additions and 5 deletions
|
@ -6,6 +6,7 @@ import logging
|
||||||
from tuyaha import TuyaApi
|
from tuyaha import TuyaApi
|
||||||
from tuyaha.tuyaapi import (
|
from tuyaha.tuyaapi import (
|
||||||
TuyaAPIException,
|
TuyaAPIException,
|
||||||
|
TuyaAPIRateLimitException,
|
||||||
TuyaFrequentlyInvokeException,
|
TuyaFrequentlyInvokeException,
|
||||||
TuyaNetException,
|
TuyaNetException,
|
||||||
TuyaServerException,
|
TuyaServerException,
|
||||||
|
@ -137,6 +138,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
) as exc:
|
) as exc:
|
||||||
raise ConfigEntryNotReady() from exc
|
raise ConfigEntryNotReady() from exc
|
||||||
|
|
||||||
|
except TuyaAPIRateLimitException as exc:
|
||||||
|
_LOGGER.error("Tuya login rate limited")
|
||||||
|
raise ConfigEntryNotReady() from exc
|
||||||
|
|
||||||
except TuyaAPIException as exc:
|
except TuyaAPIException as exc:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Connection error during integration setup. Error: %s",
|
"Connection error during integration setup. Error: %s",
|
||||||
|
|
|
@ -2,7 +2,12 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from tuyaha import TuyaApi
|
from tuyaha import TuyaApi
|
||||||
from tuyaha.tuyaapi import TuyaAPIException, TuyaNetException, TuyaServerException
|
from tuyaha.tuyaapi import (
|
||||||
|
TuyaAPIException,
|
||||||
|
TuyaAPIRateLimitException,
|
||||||
|
TuyaNetException,
|
||||||
|
TuyaServerException,
|
||||||
|
)
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
@ -103,7 +108,7 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
tuya.init(
|
tuya.init(
|
||||||
self._username, self._password, self._country_code, self._platform
|
self._username, self._password, self._country_code, self._platform
|
||||||
)
|
)
|
||||||
except (TuyaNetException, TuyaServerException):
|
except (TuyaAPIRateLimitException, TuyaNetException, TuyaServerException):
|
||||||
return RESULT_CONN_ERROR
|
return RESULT_CONN_ERROR
|
||||||
except TuyaAPIException:
|
except TuyaAPIException:
|
||||||
return RESULT_AUTH_FAILED
|
return RESULT_AUTH_FAILED
|
||||||
|
@ -249,6 +254,11 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
|
|
||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(self, user_input=None):
|
||||||
"""Handle options flow."""
|
"""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:
|
if user_input is not None:
|
||||||
dev_ids = user_input.get(CONF_LIST_DEVICES)
|
dev_ids = user_input.get(CONF_LIST_DEVICES)
|
||||||
if dev_ids:
|
if dev_ids:
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"domain": "tuya",
|
"domain": "tuya",
|
||||||
"name": "Tuya",
|
"name": "Tuya",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/tuya",
|
"documentation": "https://www.home-assistant.io/integrations/tuya",
|
||||||
"requirements": ["tuyaha==0.0.8"],
|
"requirements": ["tuyaha==0.0.9"],
|
||||||
"codeowners": ["@ollo69"],
|
"codeowners": ["@ollo69"],
|
||||||
"config_flow": true
|
"config_flow": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
|
"abort": {
|
||||||
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||||
|
},
|
||||||
"step": {
|
"step": {
|
||||||
"init": {
|
"init": {
|
||||||
"title": "Configure Tuya Options",
|
"title": "Configure Tuya Options",
|
||||||
|
|
|
@ -2208,7 +2208,7 @@ tp-connected==0.0.4
|
||||||
transmissionrpc==0.11
|
transmissionrpc==0.11
|
||||||
|
|
||||||
# homeassistant.components.tuya
|
# homeassistant.components.tuya
|
||||||
tuyaha==0.0.8
|
tuyaha==0.0.9
|
||||||
|
|
||||||
# homeassistant.components.twentemilieu
|
# homeassistant.components.twentemilieu
|
||||||
twentemilieu==0.3.0
|
twentemilieu==0.3.0
|
||||||
|
|
|
@ -1073,7 +1073,7 @@ total_connect_client==0.55
|
||||||
transmissionrpc==0.11
|
transmissionrpc==0.11
|
||||||
|
|
||||||
# homeassistant.components.tuya
|
# homeassistant.components.tuya
|
||||||
tuyaha==0.0.8
|
tuyaha==0.0.9
|
||||||
|
|
||||||
# homeassistant.components.twentemilieu
|
# homeassistant.components.twentemilieu
|
||||||
twentemilieu==0.3.0
|
twentemilieu==0.3.0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue