spinza / tuya_mqtt

3 stars 0 forks source link

TypeError creating data node and formatting homie id #1

Closed Ltty closed 11 months ago

Ltty commented 11 months ago

When setting up your server to connect a Tuya NWT Dehumidifiert to MQTT, I get the following exception. Looks like the server is for some reason unable to create a homie id. Any idea what might go wrong?

2023-08-08 12:07:48,441 - tuya_mqtt - INFO - Starting tuya_mqtt...
2023-08-08 12:07:48,441 - tuya_mqtt - DEBUG - Loading device file devices.json...
2023-08-08 12:07:48,442 - tuya_mqtt - INFO - Creating device threads...
2023-08-08 12:07:48,442 - tuya_mqtt - INFO - Starting device threads...
2023-08-08 12:07:48,443 - tuya_mqtt - INFO - Initialising device instance for NWT Dehumidifier...
2023-08-08 12:07:48,444 - tuya_mqtt - INFO - Connecting to NWT Dehumidifier...
2023-08-08 12:07:52,013 - tuya_mqtt - INFO - Fetched status of NWT Dehumidifier...
2023-08-08 12:07:52,014 - tuya_mqtt - INFO - Connected to NWT Dehumidifier...
2023-08-08 12:07:52,014 - tuya_mqtt - INFO - NWT Dehumidifier connecting to mqtt...
2023-08-08 12:07:52,017 - tuya_mqtt - INFO - NWT Dehumidifier connected to mqtt.
Exception in thread Thread-1 (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 "/opt/tuya_mqtt/./server.py", line 553, in start_device_monitor
    dm = DeviceMonitor(device_info)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/tuya_mqtt/./server.py", line 84, in __init__
    self.homie_init()
  File "/opt/tuya_mqtt/./server.py", line 470, in homie_init
    self.create_homie_device_info()
  File "/opt/tuya_mqtt/./server.py", line 379, in create_homie_device_info
    self.create_data_node()
  File "/opt/tuya_mqtt/./server.py", line 335, in create_data_node
    "__topic__": format_homie_id(dp.name),
                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/tuya_mqtt/./server.py", line 43, in format_homie_id
    return re.sub(r"[\W_]", "", s).lower()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/re/__init__.py", line 185, in sub
    return _compile(pattern, flags).sub(repl, string, count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
Ltty commented 11 months ago

Scratch that. Redownloaded the config from the tuya cloud and the issue is fixed. Seems like not all fields got fetched in the first configuration run

spinza commented 11 months ago

Yes you need to add the device to the cloud and give it 24h or so for the types to get updated. It's weird. I guess there was nothing in the device name at this stage yet.

spinza commented 11 months ago

I would also add that the code is still experimental but mostly works for me. Let me know if you discover issues. There may well be.