home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.31k stars 30.62k forks source link

Tuya Cloud | QR code reconfigure failing with "The QR code has expired. Refresh and scan again" in Smart Life App #115506

Closed AnthonyBe closed 1 month ago

AnthonyBe commented 6 months ago

The problem

I have been running the Tuya integration without issue for 12+ months. Yesterday, HA reported it need reconfiguration so I followed the process:

  1. In HA, click reconfigure which produces a Tuya QR code
  2. In Smart Life app (Android), go to 'Me', then click the QR Code scanner icon in top right corner of app.
  3. Smart Life app scanned QR Code and opened screen to confirm login
  4. After pressing 'Confirm login' button, the error "The QR code has expired. Refresh and scan again" is produced.

I tried revoking (removing) the existing access for HA (Smart Life -> Me -> Settings -> Account and Security) in case this would change the outcome, but there was no change.

What version of Home Assistant Core has the issue?

core-2024.4.3

What was the last working version of Home Assistant Core?

core-2024.4.3

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Tuya

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tuya

Diagnostics information

n/a

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No errors recorded in HA Log.

Additional information

I'm using Smart Life app v5.11.0(international) on Android

home-assistant[bot] commented 6 months ago

Hey there @tuya, @zlinoliver, @frenck, mind taking a look at this issue as it has been labeled with an integration (tuya) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `tuya` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign tuya` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


tuya documentation tuya source (message by IssueLinks)

AnthonyBe commented 6 months ago

I've managed to resolve this.

On my Android device I did a "Force Stop" of the Smart Life app and then did a 'Clear Cache' on the app. [EDIT] Then restart HA (I suspect this forces a fresh re-auth QR Code?). I failed to do this step and kept getting presented with Logging in "Non-Mobile Devices" in the Smart Life app until I did. After I relaunched the Smart Life app and re-attempted the QR code scanning process, I saw a different device name reflected in the app (see screenshots). Where previously is displayed: Logging in "Non-Mobile Devices", please make sure it was you, this time it displayed Logging in "Home Assistant", please make sure it was you When I clicked the "Confirm login" button, it was successful in re-authenticating. Screenshot_20240413_120045_Smart Life Screenshot_20240413_121539_Smart Life

These steps may be useful to others who find themselves in the same situation.

AnthonyBe commented 6 months ago

So I've just run into the same issue again, a week after first running into it, and this time, while the above steps 'worked' without error, the Tuya integration is staying in a, 'authentication expired' state.

I've seen a few issues reported with other HACS integrations connecting to Cloud services, something to do with some dependent library and async connections, since HA 2024.4.3. Is the Tuya integration also possibly affected? I've not had any issues with this integration in 12+ months until this last ~10 days.

I just went back through my logs when I reperformed the above operation and found the following:

2024-04-19 09:44:31.867 ERROR (MainThread) [custom_components.tuya_local.device] Failed to fetch device status for Ceiling fan
2024-04-19 09:44:33.989 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback <_OneTimeListener <coroutine object Client.stop at 0x7f43e575e200>>(<Event homeassistant_stop[L]>)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1322, in __call__
    self.hass.async_run_hass_job(self.listener_job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 834, in async_run_hass_job
    if hassjob.job_type is HassJobType.Callback:
       ^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/backports/functools.py", line 68, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 322, in job_type
    return self._job_type or get_hassjob_callable_job_type(self.target)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 354, in get_hassjob_callable_job_type
    raise ValueError("Coroutine not allowed to be passed to HassJob")
ValueError: Coroutine not allowed to be passed to HassJob
2024-04-19 09:44:34.995 ERROR (Thread-10) [pychromecast.socket_client] [Bedroom TV(192.168.0.61):8009] Failed to connect. No retries.
2024-04-19 09:44:36.870 WARNING (MainThread) [custom_components.tuya_local.device] Ceiling fan receive loop has terminated
2024-04-19 09:44:42.150 WARNING (MainThread) [custom_components.tuya_local.device] Madimack Elite V3 pool heat pump receive loop has terminated
2024-04-19 09:44:43.544 WARNING (MainThread) [py.warnings] /config/custom_components/hacs/utils/data.py:123: RuntimeWarning: coroutine 'Client.stop' was never awaited
  if (value := getattr(repository.data, key, default)) != default:

2024-04-19 09:44:43.777 ERROR (MainThread) [custom_components.bhyve.pybhyve.websocket] websocket connection closed
2024-04-19 09:44:43.777 WARNING (MainThread) [custom_components.bhyve.pybhyve.websocket] Websocket exception: Cannot write to closing transport
2024-04-19 09:44:43.909 WARNING (Thread-1057 (_do_shutdown)) [homeassistant.util.executor] Thread[SyncWorker_23] is still running at shutdown: File "/usr/local/lib/python3.12/threading.py", line 1030, in _bootstrap
    self._bootstrap_inner()
  File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 92, in _worker
    work_item.run()
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/nmap_tracker/__init__.py", line 300, in _run_nmap_scan
    result = self._scanner.scan(
  File "/usr/local/lib/python3.12/site-packages/nmap/nmap.py", line 278, in scan
    (self._nmap_last_output, nmap_err) = p.communicate(timeout=timeout)
  File "/usr/local/lib/python3.12/subprocess.py", line 1209, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/usr/local/lib/python3.12/subprocess.py", line 2113, in _communicate
    ready = selector.select(timeout)
  File "/usr/local/lib/python3.12/selectors.py", line 406, in select
    fd_event_list = self._selector.poll(timeout)
2024-04-19 09:44:44.902 WARNING (Thread-1057 (_do_shutdown)) [homeassistant.util.executor] Thread[SyncWorker_23] is still running at shutdown: File "/usr/local/lib/python3.12/threading.py", line 1030, in _bootstrap
    self._bootstrap_inner()
  File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 92, in _worker
    work_item.run()
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/nmap_tracker/__init__.py", line 300, in _run_nmap_scan
    result = self._scanner.scan(
  File "/usr/local/lib/python3.12/site-packages/nmap/nmap.py", line 278, in scan
    (self._nmap_last_output, nmap_err) = p.communicate(timeout=timeout)
  File "/usr/local/lib/python3.12/subprocess.py", line 1209, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/usr/local/lib/python3.12/subprocess.py", line 2113, in _communicate
    ready = selector.select(timeout)
  File "/usr/local/lib/python3.12/selectors.py", line 406, in select
    fd_event_list = self._selector.poll(timeout)
2024-04-19 09:44:44.912 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _run_async_call_action(<HomeAssistant STOPPED>, <Job track ti...t.py:1504>>)>>) at /usr/src/homeassistant/homeassistant/helpers/event.py:1504
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1508, in _run_async_call_action
    hass.async_run_hass_job(job, time_tracker_utcnow())
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1602, in _interval_listener
    hass.async_run_hass_job(self._run_job, now, background=True)
  File "/usr/src/homeassistant/homeassistant/core.py", line 840, in async_run_hass_job
    return self.async_add_hass_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 695, in async_add_hass_job
    task = self.loop.run_in_executor(None, hassjob.target, *args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 854, in run_in_executor
    self._check_default_executor()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 544, in _check_default_executor
    raise RuntimeError('Executor shutdown has been called')
RuntimeError: Executor shutdown has been called
AnthonyBe commented 6 months ago

Another person had logged same issue

https://github.com/home-assistant/core/issues/115250

dubrox commented 5 months ago

I had the same experience and found a workaround, hope it helps: https://github.com/home-assistant/core/issues/115250#issuecomment-2109848088

53NT0 commented 5 months ago

I had the same problem and your solution worked perfectly. Thank you very much.

issue-triage-workflows[bot] commented 2 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.