rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.91k stars 557 forks source link

Error when trying to use Config Flow #153

Closed cwoolum closed 3 years ago

cwoolum commented 3 years ago

When trying to use the config flow, I'm getting an error in the UI that User input malformed but it's not clear what the actual error is. I'm trying to configure a light. ID isn't set and the dropdown doesn't let me select anything so I'm not sure if that's the issue.

image

I can press enter in the Friendly name field to get it to do a submit which does a POST. Here is the body of that request.

{"brightness_lower":29,"brightness_upper":1000,"color_temp_min_kelvin":2700,"color_temp_max_kelvin":6500,"friendly_name":"Master Bedroom Recessed 4"}

and the response is

{"message": "User input malformed"}

Logs

Home Assistant Logs ``` 2020-11-11 15:59:03 DEBUG (MainThread) [custom_components.localtuya.discovery] Listening to broadcasts on UDP port 6666 and 6667 2020-11-11 15:59:07 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.86.39', 'gwId': '65580401483fdac32ac7', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'keyxfhf7ryk8ftcx', 'version': '3.3'} 2020-11-11 15:59:07 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.86.22', 'gwId': '65580401483fdac329eb', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'keyxfhf7ryk8ftcx', 'version': '3.3'} 2020-11-11 15:59:07 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.86.33', 'gwId': '65580401483fdac25c95', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'keyxfhf7ryk8ftcx', 'version': '3.3'} 2020-11-11 15:59:51 DEBUG (MainThread) [custom_components.localtuya.discovery] Listening to broadcasts on UDP port 6666 and 6667 2020-11-11 15:59:52 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.86.39', 'gwId': '65580401483fdac32ac7', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'keyxfhf7ryk8ftcx', 'version': '3.3'} 2020-11-11 15:59:52 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.86.22', 'gwId': '65580401483fdac329eb', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'keyxfhf7ryk8ftcx', 'version': '3.3'} 2020-11-11 15:59:52 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.86.33', 'gwId': '65580401483fdac25c95', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'keyxfhf7ryk8ftcx', 'version': '3.3'} 2020-11-11 16:02:29 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 153, in async_poll_devices_update device_list = await hass.async_add_executor_job(_get_updated_devices) File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 146, in _get_updated_devices tuya.poll_devices_update() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 166, in poll_devices_update return self.discover_devices() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 207, in discover_devices devices = self.discovery() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 188, in discovery response = self._request("Discovery", "discovery") File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 267, in _request self._raise_frequently_invoke( File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 292, in _raise_frequently_invoke raise TuyaFrequentlyInvokeException(message) tuyaha.tuyaapi.TuyaFrequentlyInvokeException: Method [Discovery] fails 1 time(s) using poll interval 60.0 - error: you can discovery once in 600 seconds 2020-11-11 16:04:27 DEBUG (MainThread) [custom_components.localtuya.discovery] Listening to broadcasts on UDP port 6666 and 6667 2020-11-11 16:04:27 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.86.22', 'gwId': '65580401483fdac329eb', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'keyxfhf7ryk8ftcx', 'version': '3.3'} 2020-11-11 16:04:27 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.86.33', 'gwId': '65580401483fdac25c95', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'keyxfhf7ryk8ftcx', 'version': '3.3'} 2020-11-11 16:04:32 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.86.39', 'gwId': '65580401483fdac32ac7', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': 'keyxfhf7ryk8ftcx', 'version': '3.3'} 2020-11-11 16:12:29 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 153, in async_poll_devices_update device_list = await hass.async_add_executor_job(_get_updated_devices) File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 146, in _get_updated_devices tuya.poll_devices_update() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 166, in poll_devices_update return self.discover_devices() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 207, in discover_devices devices = self.discovery() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 188, in discovery response = self._request("Discovery", "discovery") File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 267, in _request self._raise_frequently_invoke( File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 292, in _raise_frequently_invoke raise TuyaFrequentlyInvokeException(message) tuyaha.tuyaapi.TuyaFrequentlyInvokeException: Method [Discovery] fails 1 time(s) using poll interval 60.0 - error: you can discovery once in 600 seconds 2020-11-11 16:17:29 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 153, in async_poll_devices_update device_list = await hass.async_add_executor_job(_get_updated_devices) File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 146, in _get_updated_devices tuya.poll_devices_update() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 166, in poll_devices_update return self.discover_devices() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 207, in discover_devices devices = self.discovery() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 188, in discovery response = self._request("Discovery", "discovery") File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 267, in _request self._raise_frequently_invoke( File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 292, in _raise_frequently_invoke raise TuyaFrequentlyInvokeException(message) tuyaha.tuyaapi.TuyaFrequentlyInvokeException: Method [Discovery] fails 2 time(s) using poll interval 60.0 - error: you can discovery once in 600 seconds 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Started heartbeat loop 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Sending command heartbeat (device type: type_0a) 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Send payload: b'{}' 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Waiting for sequence number -100 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Sending command status (device type: type_0a) 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Send payload: b'{"gwId":"65580401483fdac329eb","devId":"65580401483fdac329eb"}' 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Waiting for sequence number 1 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Connection lost: [Errno 104] Connection reset by peer 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Closing connection 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Wait was aborted for seqno 1 2020-11-11 16:17:45 DEBUG (MainThread) [custom_components.localtuya.pytuya] [65580401483fdac329eb] Closing connection 2020-11-11 16:22:29 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 153, in async_poll_devices_update device_list = await hass.async_add_executor_job(_get_updated_devices) File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 146, in _get_updated_devices tuya.poll_devices_update() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 166, in poll_devices_update return self.discover_devices() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 207, in discover_devices devices = self.discovery() File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 188, in discovery response = self._request("Discovery", "discovery") File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 267, in _request self._raise_frequently_invoke( File "/usr/local/lib/python3.8/site-packages/tuyaha/tuyaapi.py", line 292, in _raise_frequently_invoke raise TuyaFrequentlyInvokeException(message) tuyaha.tuyaapi.TuyaFrequentlyInvokeException: Method [Discovery] fails 3 time(s) using poll interval 60.0 - error: you can discovery once in 600 seconds ```
cwoolum commented 3 years ago

So, all of a sudden, the Id dropdown started populating. It sounds like there is just some validation needed to give the user better feedback to what is broken.

postlund commented 3 years ago

Yeah, this sounds like a stupid regression to me. Some times the devices responds with an empty list of datapoints and that is what happened here. We should signal a failure and allow the user to try again if this happens.