spinza / tuya_mqtt

3 stars 0 forks source link

Blank version in device file causes issue. #4

Open psmedley opened 1 month ago

psmedley commented 1 month ago

With python 3.11, I'm seeing the following when running server.py:

Exception in thread Thread-3 (start_device_monitor):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/home/psmedley/tuya_mqtt/./server.py", line 708, in start_device_monitor
    dm = DeviceMonitor(device_info)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/psmedley/tuya_mqtt/./server.py", line 53, in __init__
    self.version = float(device_info["version"])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: ''
psmedley commented 1 month ago

OK... this is due to my blinds having: "version": "" in devices.json

spinza commented 1 month ago

Have you connected your blinds to tuya online for more than a day or two. Some of that stuff only populates after some time?

If so then I'd suggest you just replace "" with "0.1" or something (in that file). It's not critical. Will make a fix for it if you confirm that your devices has been connected to the paltform long enough.

psmedley commented 1 month ago

they've only been connected for 24 hours or so. I did regenerate devices.json this evening. I did change it to "0" and the error went away, but now I'm seeing:

2024-05-29 19:34:27,753 - tuya_mqtt - INFO - Starting tuya_mqtt...
2024-05-29 19:34:27,753 - tuya_mqtt - INFO - Creating device threads...
2024-05-29 19:34:27,753 - tuya_mqtt - INFO - Starting device threads...
2024-05-29 19:34:27,754 - tuya_mqtt - INFO - Initialising device instance for Gateway...
2024-05-29 19:34:27,754 - tuya_mqtt - INFO - Gateway connecting to mqtt...
2024-05-29 19:34:27,755 - tuya_mqtt - INFO - Connecting to Gateway...
2024-05-29 19:34:27,755 - tuya_mqtt - INFO - Gateway connected to MQTT...
2024-05-29 19:34:29,595 - tuya_mqtt - ERROR - Cound not connect to Gateway
2024-05-29 19:34:32,754 - tuya_mqtt - INFO - Initialising device instance for Paul's Blind...
2024-05-29 19:34:32,754 - tuya_mqtt - INFO - Paul's Blind connecting to mqtt...
2024-05-29 19:34:32,755 - tuya_mqtt - INFO - Connecting to Paul's Blind...
2024-05-29 19:34:32,755 - tuya_mqtt - INFO - Paul's Blind connected to MQTT...
2024-05-29 19:34:37,755 - tuya_mqtt - INFO - Initialising device instance for Julie's Blind...
2024-05-29 19:34:37,755 - tuya_mqtt - INFO - Julie's Blind connecting to mqtt...
2024-05-29 19:34:37,756 - tuya_mqtt - INFO - Connecting to Julie's Blind...
2024-05-29 19:34:37,756 - tuya_mqtt - INFO - Julie's Blind connected to MQTT...
2024-05-29 19:34:37,756 - tuya_mqtt - ERROR - Cound not connect to Julie's Blind
2024-05-29 19:34:50,757 - tuya_mqtt - ERROR - Cound not connect to Paul's Blind

Is it connecting using the cloud api or local? the blinds don't have a local IP address, only the gateway does.

spinza commented 1 month ago

Renamed this issue. Can you make a separate issue for the 2nd part please.

spinza commented 1 month ago

Actually try update your devices file again. Or set version to 3.1. It's actually important.

psmedley commented 1 month ago

I think both these issues are related. These are zigbee blinds - so support RF and zigbee control. They don't have a local IP address (and hence (I think) don't have a protocol version).

i'm assuming you're using local control, which may not work with these blinds as they don't have IP addresses. In my case, I'll need to use cloud control. I'll take a look at server.py over the weekend...

spinza commented 1 month ago

Yes, I have started to agree. If the devices don't support local control (via local connections) it's not going to work. I've set this project up to use local connections as connecting via cloud is slow and the number of API requests are limited.

Check if the gateway doesn't expose controls for the attached devices? Also fetch the devices file again after a day or two. Maybe you're lucky.

I'll probably change the code to not connect if the device doesn't have a valid version.

spinza commented 1 month ago

Actually also look at this: https://github.com/jasonacox/tinytuya/issues/117

Try the different scan options and check those.