Skip to content

Conversation

@the-ress
Copy link
Contributor

@the-ress the-ress commented Aug 5, 2023

The mqtt client now logs exceptions like Error doing job: Task exception was never retrieved [...] RoborockTimeout: id=0 Timeout after 4 seconds when it's already connected.

This PR fixes that by only calling _async_response when we actually need to connect. (Including the same-ish fix for disconnect.)

Full log entry:

2023-08-05 13:32:15.078 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved:   File "/home/vscode/.local/bin/hass", line 8, in <module>
    sys.exit(main())
  File "/home/vscode/.local/lib/python3.11/site-packages/homeassistant/__main__.py", line 214, in main
    exit_code = runner.run(runtime_conf)
  File "/home/vscode/.local/lib/python3.11/site-packages/homeassistant/runner.py", line 179, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1914, in _run_once
    handle._run()
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/workspaces/homeassistant-roborock/roborock/api.py", line 428, in get_consumable
    return Consumable.from_dict(await self.cache[CacheableAttribute.consumable].async_value())
  File "/workspaces/homeassistant-roborock/roborock/api.py", line 128, in async_value
    return await self.task.reset()
  File "/workspaces/homeassistant-roborock/roborock/util.py", line 101, in reset
    return await self._run_task()
  File "/workspaces/homeassistant-roborock/roborock/util.py", line 86, in _run_task
    response = await self.callback()
  File "/workspaces/homeassistant-roborock/roborock/api.py", line 122, in _async_value
    self._value = await self.api._send_command(self.attribute.get_command)
  File "/workspaces/homeassistant-roborock/roborock/cloud_api.py", line 195, in _send_command
    return await self.send_message(roborock_message)
  File "/workspaces/homeassistant-roborock/roborock/cloud_api.py", line 158, in send_message
    await self.validate_connection()
  File "/workspaces/homeassistant-roborock/roborock/api.py", line 312, in validate_connection
    await self.async_connect()
  File "/workspaces/homeassistant-roborock/roborock/cloud_api.py", line 145, in async_connect
    async_response = asyncio.ensure_future(self._async_response(CONNECT_REQUEST_ID))
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 649, in ensure_future
    return _ensure_future(coro_or_future, loop=loop)
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 670, in _ensure_future
    return loop.create_task(coro_or_future)
Traceback (most recent call last):
  File "/workspaces/homeassistant-roborock/roborock/api.py", line 321, in _wait_response
    raise RoborockTimeout(f"id={request_id} Timeout after {QUEUE_TIMEOUT} seconds") from None
roborock.exceptions.RoborockTimeout: id=0 Timeout after 4 seconds

@Lash-L
Copy link
Collaborator

Lash-L commented Aug 5, 2023

Can you fix the linting?

Lash-L
Lash-L previously approved these changes Aug 5, 2023
Copy link
Collaborator

@Lash-L Lash-L left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just fix the linting, but I'll leave it to @humbertogontijo as he has a better idea of how this part of the code works

@humbertogontijo
Copy link
Collaborator

This will definitely fix it. I'm just wondering about the method name, since it will not be sync

@the-ress
Copy link
Contributor Author

the-ress commented Aug 5, 2023

This will definitely fix it. I'm just wondering about the method name, since it will not be sync

The method itself still returns synchronously. (But if you have a better name, I can rename it.)

@humbertogontijo
Copy link
Collaborator

Lets just merge it. I can renamed it later if needed

@humbertogontijo humbertogontijo merged commit 1ad03be into Python-roborock:main Aug 5, 2023
@the-ress the-ress deleted the connect-task-errors branch August 5, 2023 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants