core: Tuya/Smart Life Integration fails

The problem

Trying to setup Tuya integration, but doesn’t complete successfully.

Environment

  • Home Assistant Core release with the issue: Home Assistant 0.118.4
  • Last working Home Assistant Core release (if known): N/A
  • Operating environment (OS/Container/Supervised/Core): Docker
  • Integration causing this issue: Tuya
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/tuya/

Problem-relevant configuration.yaml

N/A (configured through UI)

Traceback/Error logs

Logger: aiohttp.server
Source: components/tuya/config_flow.py:178
First occurred: 7:24:44 PM (1 occurrences)
Last logged: 7:24:44 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 118, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 172, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 210, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 69, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 130, in async_init
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 213, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/tuya/config_flow.py", line 271, in async_step_init
    query_devices = self._get_tuya_devices_filtered(
  File "/usr/src/homeassistant/homeassistant/components/tuya/config_flow.py", line 178, in _get_tuya_devices_filtered
    tuya = self.hass.data[DOMAIN][TUYA_DATA]
KeyError: 'tuya'
Logger: homeassistant.components.tuya
Source: components/tuya/__init__.py:141
Integration: Tuya (documentation, issues)
First occurred: 7:31:41 PM (1 occurrences)
Last logged: 7:31:41 PM

Connection error during integration setup. Error: you cannot auth exceed once in 60 seconds

Additional information

Account registered through Smart Life. I have a single Curtain Switch registered.

Tuya integration shows on Integrations page, but does’t show any devices / entities.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (13 by maintainers)

Most upvoted comments

I updated earlier today, and the tuya integration is now working. I cloned the code from the dev repo thinking I’d debug, oddly enough it started working. I’ll keep this thread updated once I start adding more switches through the SmartLife app.

One thing to note, I did realize creating an account with Google didn’t allow me to authenticate. Using another account, just an email and password, it did allow me to authenticate.

@ollo69 please see AlexSzlavik@5c7839b for a possible way to re-use the entry_config connection.

That’s fine, so why don’t start pushing a PR removing for the moment the new exception that will require a new TuyaHA version and more time?

The problem is that the config_flow handler performs an initial connect to check for valid credentials. Once the platform has been installed, it attempts to initialize, which involves a fresh connect. Since those two connects happen very quickly, it’s blocked by tuya via rate limit. Since I’m a hassio development n00b the solution is unclear to me. I’ll see if there is anyway to forward to session that was created in the config flow to the actual platform component.

The auth exceed error only seems to appear when setting up the integration. When I simply restart HA it does not show up.

And Integration work properly? May be Tuya introduced a new limit, I have to check this, I will do next w.e., on this days I’m in business travel…

It seems to be a key error. The const DOMAIN is tuya, however it seems that dict key isn’t within the self.hass.data dict.

EDIT: I’m only getting the key error, and not the auth exceeded error