Can't achieve to use hass.async_add_executor_job

I’m creating the config flow for worldtidesinfocustom

I’m trying to implement config_flow as a 2nd entry for the sensor.

I fall on issue that I/O are implemented in sync metod (via package requests).
From function point of view , the sensor entity call several function toward this I/O request in sync mode.

I only redirect async_update() to update() method.

To protect from the event loop , I have added hass.async_add_executor_job.
Issue : I have always a message that say the hass.async_add_executor_job shall be put just in front of of I/O whereas at this step I’m in sync … (i.e. I cannot put await …)

Any idea ?

My code is around line 486 for async_update() method

You should just pass the method and not call it:

await self._hass.async_add_executor_job(self.update)

When calling it like you do now, you do exactly the opposite of what you are trying to achieve (i.e. calling sync code from async context).


Thank you very much !
It works :slight_smile:

NB : perhaps in , the absence of () shall be highlighted.

1 Like

What if the function has multiple parameters, but I only want to pass the last parameter. How can I do that?

Please can you start a new topic, please.
I will answer.