Fix: Detected blocking call to import_module inside the event loop

This commit is contained in:
Daniel Raper
2024-05-08 10:55:21 +01:00
parent 09bab1fad6
commit e3f9f94da6
2 changed files with 9 additions and 6 deletions

View File

@@ -79,7 +79,10 @@ class WasteCollectionConfigFlow(ConfigFlow, domain=DOMAIN):
# Step 3: User fills in source arguments
async def async_step_args(self, args_input=None):
# Import source and get arguments
module = importlib.import_module(f"waste_collection_schedule.source.{self._source}")
module = await self.hass.async_add_executor_job(
importlib.import_module,
f"waste_collection_schedule.source.{self._source}"
)
title = module.TITLE
args = dict(inspect.signature(module.Source.__init__).parameters)

View File

@@ -37,11 +37,11 @@ async def async_setup_entry(hass: HomeAssistant, entry) -> bool:
entry contains data from config entry database."""
options = entry.options
shell = SourceShell.create(
source_name=entry.data[CONF_SOURCE_NAME],
source_args=entry.data[CONF_SOURCE_ARGS],
customize={}, # TODO
calendar_title=options.get(CONF_SOURCE_CALENDAR_TITLE)
shell = await hass.async_add_executor_job(SourceShell.create,
entry.data[CONF_SOURCE_NAME],
{},
entry.data[CONF_SOURCE_ARGS],
options.get(CONF_SOURCE_CALENDAR_TITLE)
)
try: