I am trying to create an integration that is a little like Sun but wraps a simple and synchronous python library which does some IO. Here is my pseudocode:
I initially had the await line in the exception handler but kept getting a âawait called outside of async functionâ error. So I made it an async function. However, async_add_executor_job returns a coroutine instead of the timetable Iâm expecting.
I suspect Iâm falling in and out of an async context somewhere but I canât figure out why, as I presume async_setup is the entry point.
The reason why I want to use async is because eventually I will be scheduling callbacks to update state using event.async_track_point_in_utc_time (a little like Sun, from where Iâm getting most of my inspiration).
RuntimeError: I/O must be done in the executor; Use `await hass.async_add_executor_job()` at custom_components/lupt/__init__.py, line 47: self.timetable = await self.hass.async_add_executor_job(lupt_cache.init_timetable(config))
Which is patently not true so Iâm not quite sure where else to go from here.
A friendly dev on Discord spotted my mistake straight away. The issue is that hass.async_add_executor_job needs a function and my code was actually executing the function I was trying to pass. hass.async_add_executor_job allows the caller to pass a parameter list:
Im also building a component where I use a Synch call to write data to a cloud DB. And Im getting the same error when calling the self.client.ingest_from_stream. I cant figure out what the âtargetâ parameter is for in await hass.async_add_executor_job, and what I need to do to provide it(I imagine ânoneâ is not enough) or what I can do to get this to work
Error:
I/O must be done in the executor; Use `await hass.async_add_executor_job()