Tasshack / dreame-vacuum

Home Assistant integration for Dreame robot vacuums with map support
https://community.home-assistant.io/t/custom-component-dreame-vacuum
MIT License
887 stars 110 forks source link

Time out on device initialization #725

Open SLAZ666 opened 2 months ago

SLAZ666 commented 2 months ago

Describe the bug Initialization of the vacuum does not work (Time out). Configuration of the device works, but the integration can not load the device.

To Reproduce Use an L10s Ultra with firmware 4.3.9_3204 like in #482 or #342

Expected behavior The integration should load the device correctly and not time out.

Additional Information (please complete the following information)

2024-09-19 19:12:03.652 ERROR (SyncWorker_3) [miio.miioprotocol] Got error when receiving: timed out 2024-09-19 19:12:03.668 WARNING (MainThread) [custom_components.dreame_vacuum] Integration start failed: Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/miio/miioprotocol.py", line 193, in send data, addr = s.recvfrom(4096) ^^^^^^^^^^^^^^^^ TimeoutError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/miio/miioprotocol.py", line 193, in send data, addr = s.recvfrom(4096) ^^^^^^^^^^^^^^^^ TimeoutError: timed out

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

Traceback (most recent call last): File "/config/custom_components/dreame_vacuum/coordinator.py", line 326, in _async_update_data await self.hass.async_add_executor_job(self.device.update) File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dreame_vacuum/dreame/device.py", line 996, in update self.connect_device() File "/config/custom_components/dreame_vacuum/dreame/device.py", line 733, in connect_device self._request_properties() File "/config/custom_components/dreame_vacuum/dreame/device.py", line 262, in _request_properties result = self._protocol.get_properties(props[:15]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dreame_vacuum/dreame/protocol.py", line 543, in get_properties return self.send("get_properties", parameters=parameters, retry_count=retry_count) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dreame_vacuum/dreame/protocol.py", line 536, in send return self.device.send(method, parameters=parameters, retry_count=retry_count) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/miio/miioprotocol.py", line 233, in send return self.send( ^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/miio/miioprotocol.py", line 241, in send raise DeviceException("No response from the device") from ex miio.exceptions.DeviceException: No response from the device

I have analysed the problem. The log points to line 262 in device.py, where the properties are requested from the device. The timeout occured in the fourth request inside the loop, so properties 45-60. I tried to get the exact property that causes the timeout, but when I requested less properties, no time out occured. I have changed the code to only request 10 properties at a time and now it initializes the device correctly. I don't really know why this works perhaps the request or response is too big for the exact combination.

So a fix that worked for me is to change lines 262 and 265 inside device.py from the value 15 to 10.

Tasshack commented 2 months ago

So a fix that worked for me is to change lines 262 and 265 inside device.py from the value 15 to 10.

This is a nice found I will investigate that, thanks.

Miio protocol has limit of maximum 15 properties at a time for all the devices that are using it but I don't think it is a size issue because vacuum can return raw map data over local protocol when it is mapping and it can grow very huge.

ManiaciaChao commented 2 weeks ago

I can confirm that this issue also occurred with my xiaomi_vacuum_c102cn. I haven't investigated it deeply yet, but setting it to 10 didn't resolve the problem. In my case, I had to adjust that value to 5.