Skip to content

Commit

Permalink
Fix issue with blocking call on listdir
Browse files Browse the repository at this point in the history
  • Loading branch information
vingerha committed Sep 15, 2024
1 parent 65c89d4 commit 03e39e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions custom_components/gtfs2/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def async_step_start_end(self, user_input: dict | None = None) -> FlowResu
"""Handle the source."""
errors: dict[str, str] = {}
if user_input is None:
datasources = get_datasources(self.hass, DEFAULT_PATH)
datasources = await get_datasources(self.hass, DEFAULT_PATH)
return self.async_show_form(
step_id="start_end",
data_schema=vol.Schema(
Expand All @@ -113,7 +113,7 @@ async def async_step_local_stops(self, user_input: dict | None = None) -> FlowRe
"""Handle the source."""
errors: dict[str, str] = {}
if user_input is None:
datasources = get_datasources(self.hass, DEFAULT_PATH)
datasources = await get_datasources(self.hass, DEFAULT_PATH)
return self.async_show_form(
step_id="local_stops",
data_schema=vol.Schema(
Expand Down Expand Up @@ -185,7 +185,7 @@ async def async_step_remove(self, user_input: dict | None = None) -> FlowResult:
"""Handle a flow initialized by the user."""
errors: dict[str, str] = {}
if user_input is None:
datasources = get_datasources(self.hass, DEFAULT_PATH)
datasources = await get_datasources(self.hass, DEFAULT_PATH)
return self.async_show_form(
step_id="remove",
data_schema=vol.Schema(
Expand Down
5 changes: 3 additions & 2 deletions custom_components/gtfs2/gtfs_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,12 @@ def get_agency_list(schedule, data):
_LOGGER.debug(f"agencies: {agencies}")
return agencies

def get_datasources(hass, path) -> dict[str]:
async def get_datasources(hass, path) -> dict[str]:
_LOGGER.debug(f"Getting datasources for path: {path}")
gtfs_dir = hass.config.path(path)
os.makedirs(gtfs_dir, exist_ok=True)
files = os.listdir(gtfs_dir)
files = await hass.async_add_executor_job(
os.listdir, gtfs_dir)
datasources = []
for file in files:
if file.endswith(".sqlite"):
Expand Down

0 comments on commit 03e39e1

Please sign in to comment.