rootnegativ1 / unifi-wifi

Home Assistant integration to change wireless passwords on UniFi Network controllers
MIT License
3 stars 0 forks source link

Detected blocking call to open inside the event loop #49

Closed rootnegativ1 closed 3 months ago

rootnegativ1 commented 3 months ago

Just noticed the following warning after updating to 2024.6

Logger: homeassistant.util.loop
Source: util/loop.py:84
First occurred: 8:12:33 AM (6 occurrences)
Last logged: 8:12:35 AM

Detected blocking call to open inside the event loop by custom integration 'unifi_wifi' at custom_components/unifi_wifi/image.py, line 278: img.save(path) (offender: /usr/local/lib/python3.12/site-packages/PIL/Image.py, line 2456: fp = builtins.open(filename, "w+b")), please create a bug report at https://github.com/rootnegativ1/unifi-wifi/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 "/config/custom_components/unifi_wifi/image.py", line 106, in async_setup_platform entities.append(UnifiWifiImage(hass, x, wlan[CONF_NAME], wlan[CONF_FILL_COLOR], wlan[CONF_BACK_COLOR])) File "/config/custom_components/unifi_wifi/image.py", line 167, in __init__ self._create_qr() File "/config/custom_components/unifi_wifi/image.py", line 278, in _create_qr img.save(path)

This seems to be related to https://developers.home-assistant.io/blog/2024/03/13/deprecate_add_run_job/

it's an issue with saving the QR code as a file

Need to figure out a way to correctly implement self.hass.async_add_executor_job() to handle this

rootnegativ1 commented 3 months ago

replacing img.save(path) with self.coordinator.hass.async_add_executor_job(img.save, path) seems to work but just seems weird to go through the coordinator to get to hass.

Maybe I'll try including self.hass=hass in __init__ . . .