leeyuentuen / localtuya

local handling for Tuya devices
GNU General Public License v3.0
72 stars 17 forks source link

Unknown error when adding Bluetooth Gateway via config flow #29

Open chris24walsh opened 1 year ago

chris24walsh commented 1 year ago

The problem

When attempting to add a Tuya Bluetooth Gateway via the config flow, it gives me an error: An unknown error occurred. See log for details.

Checking the logs gives this more detailed error message:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 390, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/config_flow.py", line 428, in async_step_basic_sub_device_info
    self.dps_strings = await validate_input(self.hass, user_input)
  File "/config/custom_components/localtuya/config_flow.py", line 260, in validate_input
    detected_dps = await interface.detect_available_dps(data[CONF_DEVICE_ID])
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 684, in detect_available_dps
    status = await self.status(cid)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 598, in status
    status = await self.exchange(ACTION_STATUS, cid=cid)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 563, in exchange
    msg = await self.dispatcher.wait_for(seqno)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 325, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

Environment

Steps to reproduce

  1. Add Integration -> LocalTuya
  2. Select gateway from list of devices.
  3. Fill in details, checking the 'Is gateway' box.
  4. Click 'SUBMIT'
  5. Error appears in the top of the dialog box, An unknown error occurred. See log for details.

Configuration configuration.yaml or config_flow

Name: Bluetooth Gateway
Local key: <redacted>
Host: 192.168.2.134
Device ID: bf12b9e35267857daeyjrf
Protocol version: 3.3 (Also tried 3.1)
Is Gateway: (checked box)

DP dump

INFO:localtuya:Detecting list of available DPS of device bf12b9e35267857daeyjrf [192.168.2.134], protocol 3.3. DEBUG:localtuya.pytuya:[bf1...jrf] Sending command 10 (device type: type_0a) DEBUG:localtuya.pytuya:[bf1...jrf] Sending payload: b'{"gwId":"bf12b9e35267857daeyjrf","devId":"bf12b9e35267857daeyjrf","uid":"bf12b9e35267857daeyjrf","t":"1673454033"}' DEBUG:localtuya.pytuya:[bf1...jrf] Command 10 waiting for sequence number 1 DEBUG:localtuya.pytuya:[bf1...jrf] Connection lost: [Errno 54] Connection reset by peer ERROR:localtuya.pytuya:[bf1...jrf] Failed to get status: Traceback (most recent call last): File "/Users/chris/.pyenv/versions/3.9.6/lib/python3.9/asyncio/locks.py", line 413, in acquire await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/chris/.pyenv/versions/3.9.6/lib/python3.9/asyncio/tasks.py", line 492, in wait_for fut.result() asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/Users/chris/dev/personal/hass/local-tuya/tuyadebug/localtuya/pytuya/init.py", line 849, in detect_available_dps data = await self.status() File "/Users/chris/dev/personal/hass/local-tuya/tuyadebug/localtuya/pytuya/init.py", line 781, in status status = await self.exchange(DP_QUERY) File "/Users/chris/dev/personal/hass/local-tuya/tuyadebug/localtuya/pytuya/init.py", line 755, in exchange msg = await self.dispatcher.wait_for(seqno, payload.cmd) File "/Users/chris/dev/personal/hass/local-tuya/tuyadebug/localtuya/pytuya/init.py", line 446, in wait_for await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout) File "/Users/chris/.pyenv/versions/3.9.6/lib/python3.9/asyncio/tasks.py", line 494, in wait_for raise exceptions.TimeoutError() from exc asyncio.exceptions.TimeoutError

Provide Home Assistant taceback/logs

This error originated from a custom integration.

Logger: custom_components.localtuya.pytuya
Source: custom_components/localtuya/pytuya/__init__.py:325
Integration: LocalTuya (documentation, issues)
First occurred: 4:24:14 PM (1 occurrences)
Last logged: 4:24:14 PM

[bf1...jrf] Failed to get status:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 390, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 702, in detect_available_dps
    status = await self.status()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 602, in status
    status = await self.exchange(ACTION_STATUS)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 563, in exchange
    msg = await self.dispatcher.wait_for(seqno)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 325, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError
This error originated from a custom integration.

Logger: custom_components.localtuya.config_flow
Source: custom_components/localtuya/pytuya/__init__.py:325
Integration: LocalTuya (documentation, issues)
First occurred: 4:24:14 PM (1 occurrences)
Last logged: 4:24:14 PM

Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 390, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/config_flow.py", line 364, in async_step_basic_info
    self.dps_strings = await validate_input(self.hass, user_input)
  File "/config/custom_components/localtuya/config_flow.py", line 270, in validate_input
    detected_dps = await interface.detect_available_dps()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 702, in detect_available_dps
    status = await self.status()
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 602, in status
    status = await self.exchange(ACTION_STATUS)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 563, in exchange
    msg = await self.dispatcher.wait_for(seqno)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 325, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

Additional information

Adding this device via the configuration.yaml 'works', but the adding the subdevices doesn't seem to work. I believe this issue may be due to the only sub-devices being bluetooth smart locks, as I understand that a lock entity is not yet defined for localtuya. Can you confirm this, or explain what else I can do here?

alexualbu commented 1 year ago

@teixeluis, excellent - that's the only DP it detected upon first scan. There are a couple of issues here:

teixeluis commented 1 year ago

Ok @alexualbu understood.

So I guess will need to wait longer for more events, since I am not physically close to the sub-device to trigger it (could remote open it but don't want to risk leaving it stuck or unlocked).

For this type of events/data from the DP's, are these coming directly from the sub-device -> BT gateway -> Home Assistant, or the gateway first sends these to the Tuya cloud and the information is collected from there?

teixeluis commented 1 year ago

@alexualbu apart from the battery state, it appears that no other DPs are readable by localtuya (even though the other DPs exist as I have listed above). I have interacted directly with the device, typing the pin, opening the lock, but still no other DPs show up when trying to add new entities via the method you mentioned.

Do you have any suggestion for debugging? As I have shared previously, in comparison tinytuya dumps the status including not just the battery state, but some other of these parameters.