DurgNomis-drol / ha_toyota

Toyota Connected Services integration for Home Assistant.
MIT License
148 stars 30 forks source link

Toyota Connected Services 2.0.3 - Detected blocking call to open inside the event #271

Open maestrigia opened 4 months ago

maestrigia commented 4 months ago

I installed the last Toyota 2.0.3 version from HACS, it failed when I added my Toyota credentials, look below the error message:

Detected blocking call to open inside the event loop by custom integration 'toyota' at custom_components/toyota/init.py, line 56: client = MyT( (offender: /usr/local/lib/python3.12/site-packages/mytoyota/controller.py, line 56: with open(str(CACHE_FILENAME), "r", encoding="utf-8") as f:), please create a bug report at https://github.com/DurgNomis-drol/ha_toyota/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle resp = await handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 77, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware response = await handler(request) File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle result = await handler(request, **request.match_info) File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 120, in post await hass.config_entries.async_reload(entry_id) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1897, in async_reload return await self.async_setup(entry_id, _lock=False) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1821, in async_setup await entry.async_setup(self.hass) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/toyota/init.py", line 56, in async_setup_entry client = MyT(

c4xp commented 4 months ago

Yep, I stopped by to confirm I have the same issue

MarcoZ76 commented 3 months ago

have the same issue too

pejotigrek commented 2 months ago

I've got probably similar/connected issue:

Detected blocking call to open with args ('/root/.cache/toyota_credentials_cache_contains_secrets', 'r')

also at customcomponents/toyota/__init_\.py, line 56, my traceback looks different tho, but in addition I see this link in my log - as a hint, may be useful: For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open

ajain-93 commented 2 months ago

Try updating to version 2.0.5, this should be fixed in the latest version.

pejotigrek commented 2 months ago

updated to 2.0.5, I've noticed that fuel level is back [it dissapeared few days earlier and I couldn't bring it back no matter what ;)], but still can see some issue similar to the above mentioned, but now it's another line in code. current warning in log:

2024-08-25 20:18:31.729 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/root/.cache/toyota_credentials_cache_contains_secrets', 'w') inside the event loop by custom integration 'toyota' at custom_components/toyota/__init__.py, line 77: vehicles = await asyncio.wait_for(client.get_vehicles(metric=metric_values), 15) (offender: /usr/local/lib/python3.12/site-packages/mytoyota/controller.py, line 203: with open(str(CACHE_FILENAME), "w", encoding="utf-8") as f:), please create a bug report at https://github.com/DurgNomis-drol/ha_toyota/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 271, in _async_update_data
    return await self.update_method()
  File "/config/custom_components/toyota/__init__.py", line 77, in async_get_vehicle_data
    vehicles = await asyncio.wait_for(client.get_vehicles(metric=metric_values), 15)
CM000n commented 2 months ago

This is not really a problem with the ha_toyota custom integration, but rather with the mytoyota Python lib used. This lib does write (non async) a file with the cached request responses to the file system when it is initialized, which causes a blocking call.

pejotigrek commented 2 months ago

This is not really a problem with the ha_toyota custom integration, but rather with the mytoyota Python lib used. This lib does write (non async) a file with the cached request responses to the file system when it is initialized, which causes a blocking call.

understood. thanks for clarification