slashback100 / presence_simulation

Home Assistant Presence Simulation
686 stars 26 forks source link

Integration fails with blocking call warnings on HA v2024.6.2 #135

Closed goofball222 closed 4 months ago

goofball222 commented 5 months ago

Repeated errors in the HA logs after presence simulation is triggered either via switch or automation. No lights are being controlled as far as I can tell.

2024-06-12 11:04:34.489 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open inside the event loop by custom integration 'presence_simulation' at custom_components/presence_simulation/__init__.py, line 187: await entity.set_start_datetime(datetime.now(pytz.timezone(hass.config.time_zone))) (offender: /usr/local/lib/python3.12/site-packages/pytz/__init__.py, line 108: return open(filename, 'rb')), please create a bug report at https://github.com/slashback100/presence_simulation/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/core.py", line 2761, in _run_service_call_catch_exceptions await coro_or_task File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service return await target(service_call) File "/config/custom_components/presence_simulation/__init__.py", line 187, in handle_presence_simulation await entity.set_start_datetime(datetime.now(pytz.timezone(hass.config.time_zone)))

bjw-s commented 5 months ago

I'm not typically one for leaving +1's, but unfortunately I'm seeing the same issue :(

I've submitted what might be a fix to get the ball rolling but my Python asyncio knowledge isn't great so I may be going about it all wrong. It does make the error go away, and my configured lights seem to be properly controlled by the integration again.