slashback100 / presence_simulation

Home Assistant Presence Simulation
423 stars 22 forks source link

Fix event loop and threading issue in handle_presence_simulation_sync #92

Closed redstone99 closed 11 months ago

redstone99 commented 11 months ago

handle_presence_simulation_sync is called by an executor, which means it may run in a thread besides the event-loop's thread. So it's not safe to call hass.async_create_task, which uses loop.create_task, which checks that it's only called from the event thread. Instead I think it's necessary to call hass.create_task, which is safe to call from non-event-loop threads.

I encountered this issue after an update, when I started getting errors in presence simulation from the asyncio loop complaining that create_task was called from the wrong thread.