mdeweerd / zha-toolkit

🧰 Zigbee Home Assistant Toolkit - service for "rare" Zigbee operations using ZHA on Home Assistant
GNU General Public License v3.0
171 stars 17 forks source link

Fix for blocking call issue #227

Open benschumacher opened 2 months ago

benschumacher commented 2 months ago

This is a PR to address #224. It works for me, but I didn't spend the effort to fully grok how this fits into the bigger scheme.

CordoWEB commented 2 months ago

I tested this patch on HAS 2024.5.2, all seems to be OK 👍 Thank you so so much 💯

erkr commented 2 months ago

@benschumacher I applied the patch with success as well! Thanks

corinevm commented 1 month ago

I applied the patch today and it's working well! Thanks a lot!

Core 2024.6.1 Supervisor 2024.06.0 Operating System 12.3 Frontend 20240605.0

garie commented 2 weeks ago

I applied the patch but get a new warning now, which happens inside an if so the others who have not seen issues may not be falling into that case. I believe there is another place that needs an await but is more complicated because the surrounding function is not async:

Logger: homeassistant.util.loop
Source: util/loop.py:84
First occurred: 10:32:37 AM (1 occurrences)
Last logged: 10:32:37 AM

2024-06-22 10:32:37.360 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open inside the event loop by custom integration 'zha_toolkit' at custom_components/zha_toolkit/utils.py, line 84: with open(fname, encoding="utf_8") as infile: (offender: /config/custom_components/zha_toolkit/utils.py, line 84: with open(fname, encoding="utf_8") as infile:), please create a bug report at https://github.com/mdeweerd/zha-toolkit/issues
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 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/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component
result = await _async_setup_component(hass, domain, config)
File "/usr/src/homeassistant/homeassistant/setup.py", line 402, in _async_setup_component
result = await task
File "/config/custom_components/zha_toolkit/__init__.py", line 655, in async_setup
register_services(hass)
File "/config/custom_components/zha_toolkit/__init__.py", line 862, in register_services
LOADED_VERSION = u.getVersion()
File "/config/custom_components/zha_toolkit/utils.py", line 84, in getVersion
with open(fname, encoding="utf_8") as infile:
erkr commented 2 weeks ago

Yes saw that one as well but for me only at startup. The previous one seemed to happen at every service call